r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / filesndfile.C
blobffb6dd062cd6759b8438e086d1b68506412fd951
1 #include "assets.h"
2 #include "bitspopup.h"
3 #include "clip.h"
4 #include "file.h"
5 #include "filesndfile.h"
6 #include "mwindow.inc"
8 #include <libintl.h>
9 #define _(String) gettext(String)
10 #define gettext_noop(String) String
11 #define N_(String) gettext_noop (String)
13 #ifdef HAVE_LIBSNDFILE_0
14 // Routines for libsndfile 0.x.x
16 FileSndFile::FileSndFile(Asset *asset, File *file)
17  : FileBase(asset, file)
19         temp_double = 0;
20         temp_allocated = 0;
21         fd_config.format = 0;
24 FileSndFile::~FileSndFile()
26         if(temp_double) delete [] temp_double;
29 int FileSndFile::check_sig(Asset *asset)
31 //printf("FileSndFile::check_sig 1\n");
32         int result = 0;
33         SF_INFO fd_config;
34         fd_config.format = 0;
35 //printf("FileSndFile::check_sig 1\n");
36         SNDFILE *fd = sf_open_read(asset->path, &fd_config);
37 //printf("FileSndFile::check_sig 1 %p\n", fd);
39         if(fd)
40         {
41                 sf_close(fd);
42                 result = 1;
43         }
44         else
45                 result = 0;
46 //printf("FileSndFile::check_sig 2\n");
47         return result;
50 void FileSndFile::asset_to_format()
52         switch(asset->format)
53         {
54                 case FILE_PCM:  fd_config.format = SF_FORMAT_RAW;  break;
55                 case FILE_WAV:  fd_config.format = SF_FORMAT_WAV;  break;
56                 case FILE_AU:   fd_config.format = SF_FORMAT_AU;   break;
57                 case FILE_AIFF: fd_config.format = SF_FORMAT_AIFF; break;
58         }
60 // Not all of these are allowed in all sound formats.
61 // Raw can't be float.
62         switch(asset->bits)
63         {
64                 case BITSLINEAR8:
65                 case BITSLINEAR16:
66                 case BITSLINEAR24:
67                         if(asset->format != FILE_PCM)
68                         {
69                                 fd_config.format |= SF_FORMAT_PCM;
70                         }
71                         else
72                         {
73                                 if(asset->byte_order)
74                                         fd_config.format |= SF_FORMAT_PCM_LE;
75                                 else
76                                         fd_config.format |= SF_FORMAT_PCM_BE;
77                         }
78                         fd_config.pcmbitwidth = asset->bits;
79 //printf("FileSndFile::asset_to_format 1 %x %d\n", fd_config.format, fd_config.pcmbitwidth);
80                         break;
82                 case BITSULAW: 
83                         fd_config.format |= SF_FORMAT_ULAW; 
84                         fd_config.pcmbitwidth = 16;
85                         break;
87                 case BITSFLOAT: 
88 //printf("FileSndFile::asset_to_format 1\n");
89                         fd_config.format |= SF_FORMAT_FLOAT; 
90                         fd_config.pcmbitwidth = 16;
91                         break;
93                 case BITS_ADPCM: 
94                         if(fd_config.format == FILE_WAV)
95                                 fd_config.format |= SF_FORMAT_MS_ADPCM;
96                         else
97                                 fd_config.format |= SF_FORMAT_IMA_ADPCM; 
98                         fd_config.pcmbitwidth = 16;
99                         break;
100         }
102         fd_config.seekable = 1;
103         fd_config.samplerate = asset->sample_rate;
104         fd_config.channels  = asset->channels;
105 //printf("FileSndFile::asset_to_format %x %d %d\n", fd_config.format, fd_config.pcmbitwidth, fd_config.channels);
108 void FileSndFile::format_to_asset()
110 //printf("FileSndFile::format_to_asset 1\n");
111         asset->byte_order = 0;
112         asset->signed_ = 1;
114         if(asset->format == 0)
115                 switch(fd_config.format & SF_FORMAT_TYPEMASK)
116                 {
117                         case SF_FORMAT_WAV:  
118                                 asset->format = FILE_WAV;  
119                                 asset->byte_order = 1;
120                                 asset->header = 44;
121                                 break;
122                         case SF_FORMAT_AIFF: asset->format = FILE_AIFF; break;
123                         case SF_FORMAT_AU:   asset->format = FILE_AU;   break;
124                         case SF_FORMAT_AULE: asset->format = FILE_AU;   break;
125                         case SF_FORMAT_RAW:  asset->format = FILE_PCM;  break;
126                         case SF_FORMAT_PAF:  asset->format = FILE_SND;  break;
127                         case SF_FORMAT_SVX:  asset->format = FILE_SND;  break;
128                         case SF_FORMAT_NIST: asset->format = FILE_SND;  break;
129                 }
131         switch(fd_config.format & SF_FORMAT_SUBMASK)
132         {
133                 case SF_FORMAT_FLOAT: 
134                         asset->bits = BITSFLOAT; 
135                         break;
136                 case SF_FORMAT_ULAW: 
137                         asset->bits = BITSULAW; 
138                         break;
139                 case SF_FORMAT_IMA_ADPCM:
140                 case SF_FORMAT_MS_ADPCM:
141                         asset->bits = BITS_ADPCM;
142                         break;
143                 case SF_FORMAT_PCM:
144                         asset->bits = fd_config.pcmbitwidth;
145                         break;
146                 case SF_FORMAT_PCM_BE:
147                         asset->byte_order = 0;
148                         asset->bits = fd_config.pcmbitwidth;
149                         break;
150                 case SF_FORMAT_PCM_LE:
151                         asset->byte_order = 1;
152                         asset->bits = fd_config.pcmbitwidth;
153                         break;
154                 case SF_FORMAT_PCM_S8:
155                         asset->signed_ = 1;
156                         asset->bits = BITSLINEAR8;
157                         break;
158                 case SF_FORMAT_PCM_U8:
159                         asset->signed_ = 0;
160                         asset->bits = BITSLINEAR8;
161                         break;
162         }
164         asset->audio_data = 1;
165         asset->audio_length = fd_config.samples;
166         if(!asset->sample_rate)
167                 asset->sample_rate = fd_config.samplerate;
168         asset->channels = fd_config.channels;
169 //printf("FileSndFile::format_to_asset %x %d %d %x\n", fd_config.format & SF_FORMAT_TYPEMASK, fd_config.pcmbitwidth, fd_config.samples, fd_config.format & SF_FORMAT_SUBMASK);
170 //asset->dump();
173 int FileSndFile::open_file(int rd, int wr)
175         int result = 0;
176         this->rd = rd;
177         this->wr = wr;
179         if(rd)
180         {
181                 if(asset->format == FILE_PCM)
182                 {
183                         asset_to_format();
184                         fd = sf_open_read(asset->path, &fd_config);
185                         format_to_asset();
186                 }
187                 else
188                 {
189                         fd = sf_open_read(asset->path, &fd_config);
190 // Doesn't calculate the length
191                         format_to_asset();
192                 }
193         }
194         else
195         if(wr)
196         {
197 //printf("FileSndFile::open_file 1\n");
198                 asset_to_format();
199 //printf("FileSndFile::open_file 1\n");
200                 fd = sf_open_write(asset->path, &fd_config);
201 //printf("FileSndFile::open_file 2 %p\n", fd);
202         }
204         if(!fd) 
205         {
206                 result = 1;
207                 printf("FileSndFile::open_file:\n");
208                 sf_perror(0);
209         }
211         return result;
214 int FileSndFile::close_file()
216 //printf("FileSndFile::close_file 1\n");
217         sf_close(fd);
218         FileBase::close_file();
219         fd_config.format = 0;
220         return 0;
223 int FileSndFile::set_audio_position(int64_t sample)
225 //printf("FileSndFile::set_audio_position %ld\n", sample);
226 // Commented out /* && psf->dataoffset */ in sndfile.c: 761
227         if(sf_seek(fd, sample, SEEK_SET) < 0)
228         {
229                 printf("FileSndFile::set_audio_position %lld: failed\n", sample);
230                 sf_perror(fd);
231                 return 1;
232         }
233         return 0;
236 int FileSndFile::read_samples(double *buffer, int64_t len)
238         int result = 0;
240 // Get temp buffer for interleaved channels
241         if(len <= 0 || len > 1000000)
242                 printf("FileSndFile::read_samples len=%d\n", len);
244         if(!buffer)
245                 printf("FileSndFile::read_samples buffer=%p\n", buffer);
247 //printf("FileSndFile::read_samples 1 current_sample=%d len=%d\n", file->current_sample, len);
248         if(temp_allocated && temp_allocated < len)
249         {
250 //printf("FileSndFile::read_samples 1\n");
251                 delete [] temp_double;
252                 temp_double = 0;
253                 temp_allocated = 0;
254         }
256         if(!temp_allocated)
257         {
258                 temp_allocated = len;
259 //printf("FileSndFile::read_samples 2\n");
260                 temp_double = new double[len * asset->channels];
261         }
263 //printf("FileSndFile::read_samples 3\n");
264         result = !sf_read_double(fd, temp_double, len * asset->channels, 1);
265 //printf("FileSndFile::read_samples 4\n");
267         if(result)
268                 printf("FileSndFile::read_samples fd=%p temp_double=%p len=%d asset=%p asset->channels=%d\n",
269                         fd, temp_double, len, asset, asset->channels);
271 //printf("FileSndFile::read_samples 4\n");
272 // Extract single channel
273         for(int i = 0, j = file->current_channel; 
274                 i < len;
275                 i++, j += asset->channels)
276         {
277                 buffer[i] = temp_double[j];
278         }
279 //printf("FileSndFile::read_samples 6\n");
281         return result;
284 int FileSndFile::write_samples(double **buffer, int64_t len)
286         int result = 0;
288 // Get temp buffer for interleaved channels
289 //printf("FileSndFile::read_samples 1\n");
290         if(temp_allocated && temp_allocated < len)
291         {
292                 temp_allocated = 0;
293                 delete [] temp_double;
294                 temp_double = 0;
295         }
297 //printf("FileSndFile::read_samples 2\n");
298         if(!temp_allocated)
299         {
300                 temp_allocated = len;
301                 temp_double = new double[len * asset->channels];
302         }
304 // Interleave channels
305         for(int i = 0; i < asset->channels; i++)
306         {
307                 for(int j = 0; j < len; j++)
308                 {
309                         double sample = buffer[i][j];
310 // Libsndfile does not limit values
311 //if(sample > 1.0 || sample < -1.0) printf("FileSndFile::write_samples %f\n", sample);
312                         CLAMP(sample, -1.0, (32767.0 / 32768.0));
313                         temp_double[j * asset->channels + i] = sample;
314                 }
315         }
316         
317         result = !sf_writef_double(fd, temp_double, len, 1);
319         return result;
322 void FileSndFile::get_parameters(BC_WindowBase *parent_window, 
323                 Asset *asset, 
324                 BC_WindowBase* &format_window,
325                 int audio_options,
326                 int video_options)
328         if(audio_options)
329         {
330                 SndFileConfig *window = new SndFileConfig(parent_window, asset);
331                 format_window = window;
332                 window->create_objects();
333                 window->run_window();
334                 delete window;
335         }
338 SndFileConfig::SndFileConfig(BC_WindowBase *parent_window, Asset *asset)
339  : BC_Window(PROGRAM_NAME ": Audio Compression",
340         parent_window->get_abs_cursor_x(),
341         parent_window->get_abs_cursor_y(),
342         250,
343         200)
345         this->parent_window = parent_window;
346         this->asset = asset;
349 SndFileConfig::~SndFileConfig()
351         if(bits_popup) delete bits_popup;
353 int SndFileConfig::create_objects()
355         int x = 10, y = 10;
357         bits_popup = 0;
358         switch(asset->format)
359         {
360                 case FILE_WAV:
361                 case FILE_PCM:
362                 case FILE_AIFF:
363                         add_tool(new BC_Title(x, y, _("Compression:")));
364                         y += 25;
365                         if(asset->format == FILE_WAV)
366                                 bits_popup = new BitsPopup(this, x, y, &asset->bits, 0, 0, 1, 1, 0);
367                         else
368                                 bits_popup = new BitsPopup(this, x, y, &asset->bits, 0, 0, 0, 0, 0);
369                         y += 40;
370                         bits_popup->create_objects();
371                         break;
372         }
374         x = 10;
375         if(asset->format != FILE_AU)
376                 add_subwindow(new BC_CheckBox(x, y, &asset->dither, _("Dither")));
377         y += 30;
378         if(asset->format == FILE_PCM)
379         {
380                 add_subwindow(new BC_CheckBox(x, y, &asset->signed_, _("Signed")));
381                 y += 35;
382                 add_subwindow(new BC_Title(x, y, _("Byte order:")));
383                 add_subwindow(hilo = new SndFileHILO(this, x + 100, y));
384                 add_subwindow(lohi = new SndFileLOHI(this, x + 170, y));
385         }
386         add_subwindow(new BC_OKButton(this));
387         return 0;
390 int SndFileConfig::close_event()
392         set_done(0);
393         return 1;
398 SndFileHILO::SndFileHILO(SndFileConfig *gui, int x, int y)
399  : BC_Radial(x, y, gui->asset->byte_order == 0, _("Hi Lo"))
401         this->gui = gui;
403 int SndFileHILO::handle_event()
405         gui->asset->byte_order = 0;
406         gui->lohi->update(0);
407         return 1;
413 SndFileLOHI::SndFileLOHI(SndFileConfig *gui, int x, int y)
414  : BC_Radial(x, y, gui->asset->byte_order == 1, _("Lo Hi"))
416         this->gui = gui;
418 int SndFileLOHI::handle_event()
420         gui->asset->byte_order = 1;
421         gui->hilo->update(0);
422         return 1;
424 #else // #ifdef HAVE_LIBSNDFILE_0
425 // Updated, libsndfile 1.x.x compatible routines
427 FileSndFile::FileSndFile(Asset *asset, File *file)
428  : FileBase(asset, file)
430         temp_double = 0;
431         temp_allocated = 0;
432         fd_config.format = 0;
435 FileSndFile::~FileSndFile()
437         if(temp_double) delete [] temp_double;
440 int FileSndFile::check_sig(Asset *asset)
442 //printf("FileSndFile::check_sig 1\n");
443         int result = 0;
444         SF_INFO fd_config;
445         fd_config.format = 0;
446 //printf("FileSndFile::check_sig 1\n");
447         SNDFILE *fd = sf_open(asset->path, SFM_READ, &fd_config);
448 //printf("FileSndFile::check_sig 1\n");
450         if(fd)
451         {
452                 sf_close(fd);
453                 result = 1;
454         }
455         else
456                 result = 0;
457 //printf("FileSndFile::check_sig 2\n");
458         return result;
461 void FileSndFile::asset_to_format()
463         // Set the file format
464         switch(asset->format)
465         {
466                 case FILE_PCM:  fd_config.format = SF_FORMAT_RAW;  break;
467                 case FILE_WAV:  fd_config.format = SF_FORMAT_WAV;  break;
468                 case FILE_AU:   fd_config.format = SF_FORMAT_AU;   break;
469                 case FILE_AIFF: fd_config.format = SF_FORMAT_AIFF; break;
470         }
472         // Set the coding format - not all file/coding format combinations
473     // are supported
474         switch(asset->bits)
475         {
476                 case BITSLINEAR8:
477                         if (asset->signed_)
478                         {
479                                 fd_config.format |= SF_FORMAT_PCM_S8;
480                         }
481                         else
482                         {
483                                 fd_config.format |= SF_FORMAT_PCM_U8;
484                         }
485                         break;
487                 case BITSLINEAR16:
488                         fd_config.format |= SF_FORMAT_PCM_16;
489                         break;
491                 case BITSLINEAR24:
492                         fd_config.format |= SF_FORMAT_PCM_24;
493                         break;
495                 case BITSFLOAT: 
496                         // RAW can't be float
497                         if (asset->format != FILE_PCM)
498                         {
499                                 fd_config.format |= SF_FORMAT_FLOAT; 
500                         }
501                         break;
503                 case BITSULAW: 
504                         // FIXME: can RAW be ADPCM?
505                         fd_config.format |= SF_FORMAT_ULAW; 
506                         break;
508                 case BITS_ADPCM: 
509                         // FIXME: can RAW be ADPCM?
510                         if(fd_config.format == FILE_WAV)
511                         {
512                                 fd_config.format |= SF_FORMAT_MS_ADPCM;
513                         }
514                         else
515                         {
516                                 fd_config.format |= SF_FORMAT_IMA_ADPCM; 
517                         }
518                         break;
519         }
521         if(asset->byte_order)
522         {
523                 fd_config.format |= SF_ENDIAN_LITTLE;
524         }
525         else
526         {
527                 fd_config.format |= SF_ENDIAN_BIG;
528         }
530         fd_config.seekable = 1;
531         fd_config.samplerate = asset->sample_rate;
532         fd_config.channels  = asset->channels;
535 void FileSndFile::format_to_asset()
537 //printf("FileSndFile::format_to_asset 1\n");
538         asset->byte_order = 0;
539         asset->signed_ = 1;
541         if(asset->format == 0)
542         {
543                 switch(fd_config.format & SF_FORMAT_TYPEMASK)
544                 {
545                         case SF_FORMAT_WAV:  
546                                 asset->format = FILE_WAV;  
547                                 asset->byte_order = 1;
548                                 asset->header = 44;
549                                 break;
550                         case SF_FORMAT_AIFF: asset->format = FILE_AIFF; break;
551                         case SF_FORMAT_AU:   asset->format = FILE_AU;   break;
552 //                      case SF_FORMAT_AULE: asset->format = FILE_AU;   break;
553                         case SF_FORMAT_RAW:  asset->format = FILE_PCM;  break;
554                         case SF_FORMAT_PAF:  asset->format = FILE_SND;  break;
555                         case SF_FORMAT_SVX:  asset->format = FILE_SND;  break;
556                         case SF_FORMAT_NIST: asset->format = FILE_SND;  break;
557                 }
558         }
560         switch(fd_config.format & SF_FORMAT_SUBMASK)
561         {
562                 case SF_FORMAT_FLOAT: 
563                         asset->bits = BITSFLOAT; 
564                         break;
566                 case SF_FORMAT_ULAW: 
567                         asset->bits = BITSULAW; 
568                         break;
570                 case SF_FORMAT_IMA_ADPCM:
571                 case SF_FORMAT_MS_ADPCM:
572                         asset->bits = BITS_ADPCM;
573                         break;
575                 case SF_FORMAT_PCM_16:
576                         asset->signed_ = 1;
577                         asset->bits = 16;
578                         break;
580                 case SF_FORMAT_PCM_24:
581                         asset->signed_ = 1;
582                         asset->bits = 24;
583                         break;
585                 case SF_FORMAT_PCM_32:
586                         asset->signed_ = 1;
587                         asset->bits = 32;
588                         break;
590                 case SF_FORMAT_PCM_S8:
591                         asset->signed_ = 1;
592                         asset->bits = BITSLINEAR8;
593                         break;
595                 case SF_FORMAT_PCM_U8:
596                         asset->signed_ = 0;
597                         asset->bits = BITSLINEAR8;
598                         break;
599         }
601         switch(fd_config.format & SF_FORMAT_ENDMASK)
602         {
603                 case SF_ENDIAN_LITTLE:
604                         asset->byte_order = 1;
605                         break;
606                 case SF_ENDIAN_BIG:
607                         asset->byte_order = 0;
608                         break;
609         }
611         asset->audio_data = 1;
612         asset->audio_length = fd_config.frames;
614         if(!asset->sample_rate)
615                 asset->sample_rate = fd_config.samplerate;
617         asset->channels = fd_config.channels;
619 //printf("FileSndFile::format_to_asset %x %d %d %x\n", fd_config.format & SF_FORMAT_TYPEMASK, fd_config.pcmbitwidth, fd_config.samples, fd_config.format & SF_FORMAT_SUBMASK);
620 //asset->dump();
623 int FileSndFile::open_file(int rd, int wr)
625         int result = 0;
626         this->rd = rd;
627         this->wr = wr;
629         if(rd)
630         {
631                 if(asset->format == FILE_PCM)
632                 {
633                         asset_to_format();
634                         fd = sf_open(asset->path, SFM_READ, &fd_config);
635                         format_to_asset();
636                 }
637                 else
638                 {
639                         fd = sf_open(asset->path, SFM_READ, &fd_config);
640 // Doesn't calculate the length
641                         format_to_asset();
642                 }
643         }
644         else
645         {
646                 if(wr)
647                 {
648 //printf("FileSndFile::open_file 1\n");
649                         asset_to_format();
650 //printf("FileSndFile::open_file 1\n");
651                         fd = sf_open(asset->path, SFM_WRITE, &fd_config);
652 //printf("FileSndFile::open_file 2 %p\n", fd);
653                 }
654         }
656         if(!fd) 
657         {
658                 result = 1;
659                 printf("FileSndFile::open_file:\n");
660                 sf_perror(0);
661         }
663         return result;
666 int FileSndFile::close_file()
668 //printf("FileSndFile::close_file 1\n");
669         sf_close(fd);
670         FileBase::close_file();
671         fd_config.format = 0;
672         return 0;
675 int FileSndFile::set_audio_position(int64_t sample)
677 //printf("FileSndFile::set_audio_position %ld\n", sample);
678 // Commented out /* && psf->dataoffset */ in sndfile.c: 761
679         if(sf_seek(fd, sample, SEEK_SET) < 0)
680         {
681                 printf("FileSndFile::set_audio_position %ld: failed\n", sample);
682                 sf_perror(fd);
683                 return 1;
684         }
685         return 0;
688 int FileSndFile::read_samples(double *buffer, int64_t len)
690         int result = 0;
692 // Get temp buffer for interleaved channels
693         if(len <= 0 || len > 1000000)
694                 printf("FileSndFile::read_samples len=%d\n", len);
696         if(!buffer)
697                 printf("FileSndFile::read_samples buffer=%p\n", buffer);
699 //printf("FileSndFile::read_samples 1 current_sample=%d len=%d\n", file->current_sample, len);
700         if(temp_allocated && temp_allocated < len)
701         {
702 //printf("FileSndFile::read_samples 1\n");
703                 delete [] temp_double;
704                 temp_double = 0;
705                 temp_allocated = 0;
706         }
708         if(!temp_allocated)
709         {
710                 temp_allocated = len;
711 //printf("FileSndFile::read_samples 2\n");
712                 temp_double = new double[len * asset->channels];
713         }
715 //printf("FileSndFile::read_samples 3\n");
716         result = !sf_read_double(fd, temp_double, len * asset->channels);
717 //printf("FileSndFile::read_samples 4\n");
719         if(result)
720                 printf("FileSndFile::read_samples fd=%p temp_double=%p len=%d asset=%p asset->channels=%d\n",
721                         fd, temp_double, len, asset, asset->channels);
723 //printf("FileSndFile::read_samples 4\n");
724 // Extract single channel
725         for(int i = 0, j = file->current_channel; 
726                 i < len;
727                 i++, j += asset->channels)
728         {
729                 buffer[i] = temp_double[j];
730         }
731 //printf("FileSndFile::read_samples 6\n");
733         return result;
736 int FileSndFile::write_samples(double **buffer, int64_t len)
738         int result = 0;
740 // Get temp buffer for interleaved channels
741 //printf("FileSndFile::read_samples 1\n");
742         if(temp_allocated && temp_allocated < len)
743         {
744                 temp_allocated = 0;
745                 delete [] temp_double;
746                 temp_double = 0;
747         }
749 //printf("FileSndFile::read_samples 2\n");
750         if(!temp_allocated)
751         {
752                 temp_allocated = len;
753                 temp_double = new double[len * asset->channels];
754         }
756 // Interleave channels
757         for(int i = 0; i < asset->channels; i++)
758         {
759                 for(int j = 0; j < len; j++)
760                 {
761                         double sample = buffer[i][j];
762 // Libsndfile does not limit values
763 //if(sample > 1.0 || sample < -1.0) printf("FileSndFile::write_samples %f\n", sample);
764                         CLAMP(sample, -1.0, (32767.0 / 32768.0));
765                         temp_double[j * asset->channels + i] = sample;
766                 }
767         }
768         
769         result = !sf_writef_double(fd, temp_double, len);
771         return result;
774 void FileSndFile::get_parameters(BC_WindowBase *parent_window, 
775                 Asset *asset, 
776                 BC_WindowBase* &format_window,
777                 int audio_options,
778                 int video_options)
780         if(audio_options)
781         {
782                 SndFileConfig *window = new SndFileConfig(parent_window, asset);
783                 format_window = window;
784                 window->create_objects();
785                 window->run_window();
786                 delete window;
787         }
790 SndFileConfig::SndFileConfig(BC_WindowBase *parent_window, Asset *asset)
791  : BC_Window(PROGRAM_NAME ": Audio Compression",
792         parent_window->get_abs_cursor_x(),
793         parent_window->get_abs_cursor_y(),
794         250,
795         200)
797         this->parent_window = parent_window;
798         this->asset = asset;
801 SndFileConfig::~SndFileConfig()
803         if(bits_popup) delete bits_popup;
805 int SndFileConfig::create_objects()
807         int x = 10, y = 10;
809         bits_popup = 0;
810         switch(asset->format)
811         {
812                 case FILE_WAV:
813                 case FILE_PCM:
814                 case FILE_AIFF:
815                         add_tool(new BC_Title(x, y, _("Compression:")));
816                         y += 25;
817                         if(asset->format == FILE_WAV)
818                                 bits_popup = new BitsPopup(this, x, y, &asset->bits, 0, 0, 1, 1, 0);
819                         else
820                                 bits_popup = new BitsPopup(this, x, y, &asset->bits, 0, 0, 0, 0, 0);
821                         y += 40;
822                         bits_popup->create_objects();
823                         break;
824         }
826         x = 10;
827         if(asset->format != FILE_AU)
828                 add_subwindow(new BC_CheckBox(x, y, &asset->dither, _("Dither")));
829         y += 30;
830         if(asset->format == FILE_PCM)
831         {
832                 add_subwindow(new BC_CheckBox(x, y, &asset->signed_, _("Signed")));
833                 y += 35;
834                 add_subwindow(new BC_Title(x, y, _("Byte order:")));
835                 add_subwindow(hilo = new SndFileHILO(this, x + 100, y));
836                 add_subwindow(lohi = new SndFileLOHI(this, x + 170, y));
837         }
838         add_subwindow(new BC_OKButton(this));
839         return 0;
842 int SndFileConfig::close_event()
844         set_done(0);
845         return 1;
850 SndFileHILO::SndFileHILO(SndFileConfig *gui, int x, int y)
851  : BC_Radial(x, y, gui->asset->byte_order == 0, _("Hi Lo"))
853         this->gui = gui;
855 int SndFileHILO::handle_event()
857         gui->asset->byte_order = 0;
858         gui->lohi->update(0);
859         return 1;
865 SndFileLOHI::SndFileLOHI(SndFileConfig *gui, int x, int y)
866  : BC_Radial(x, y, gui->asset->byte_order == 1, _("Lo Hi"))
868         this->gui = gui;
870 int SndFileLOHI::handle_event()
872         gui->asset->byte_order = 1;
873         gui->hilo->update(0);
874         return 1;
876 #endif // #ifdef HAVE_LIBSNDFILE_0