On Thu, 2014-09-25 at 21:02 +0100, Harry van Haaren wrote:
On Thu, Sep 25, 2014 at 8:50 PM, Joël Krähemann
<weedlight(a)gmail.com> wrote:
Does someone know about writing WAV using
libsndfile?
My file becomes 174M big as using sf_writef_short() within 8s
Are you sure you're only writing each sample once? Sounds like there's
an error in writing "nframe" samples for each sample or something.
Its pretty easy: and there's a brilliant to-the-point blog post on
using C++ interface (sndfile.hh) here:
http://parumi.wordpress.com/2007/12/16/how-to-write-wav-files-in-c-using-li…
If there's still issues, please pastebin some code, or ask a more
specific question :)
HTH, -Harry
There probably only those three functions involved:
void
ags_export_output_launch(AgsTask *task)
{
AgsExportOutput *export_output;
AgsExportThread *export_thread;
AgsDevout *devout;
AgsAudioFile *audio_file;
gchar *filename;
export_output = AGS_EXPORT_OUTPUT(task);
devout = export_output->devout;
export_thread = export_output->export_thread;
filename = export_output->filename;
/* open read/write audio file */
audio_file = ags_audio_file_new(filename,
devout,
0, devout->dsp_channels);
audio_file->samplerate = (int) devout->frequency;
audio_file->channels = devout->dsp_channels;
// audio_file->format = devout->bits;
audio_file->frames = export_output->frames;
ags_audio_file_rw_open(audio_file,
TRUE);
g_message("export output");
/* start export thread */
g_object_set(G_OBJECT(export_thread),
"audio-file\0", audio_file,
NULL);
ags_thread_start(export_thread);
}
void
ags_export_thread_run(AgsThread *thread)
{
AgsExportThread *export_thread;
AgsDevout *devout;
export_thread = AGS_EXPORT_THREAD(thread);
devout = thread->devout;
if((AGS_DEVOUT_BUFFER1 & (devout->flags)) != 0){
ags_audio_file_write(export_thread->audio_file,
devout->buffer[0], devout->buffer_size);
}else if((AGS_DEVOUT_BUFFER2 & (devout->flags)) != 0){
ags_audio_file_write(export_thread->audio_file,
devout->buffer[1], devout->buffer_size);
}else if((AGS_DEVOUT_BUFFER3 & (devout->flags)) != 0){
ags_audio_file_write(export_thread->audio_file,
devout->buffer[2], devout->buffer_size);
}else if((AGS_DEVOUT_BUFFER0 & (devout->flags)) != 0){
ags_audio_file_write(export_thread->audio_file,
devout->buffer[3], devout->buffer_size1);
}
}
void
ags_sndfile_write(AgsPlayable *playable, signed short *buffer, guint
buffer_length)
{
AgsSndfile *sndfile;
sf_count_t multi_frames, retval;
sndfile = AGS_SNDFILE(playable);
multi_frames = buffer_length;
retval = sf_write_short(sndfile->file, buffer, multi_frames);
if(retval > multi_frames){
// sf_seek(sndfile->file, (multi_frames - retval),
SEEK_CUR);
}
}