Consistent samplerate handling for playback and recording - Alex
authorterminatorX <>
Sun, 23 Mar 2003 23:23:43 +0000 (23:23 +0000)
committerterminatorX <>
Sun, 23 Mar 2003 23:23:43 +0000 (23:23 +0000)
src/tX_audiodevice.cc
src/tX_audiodevice.h
src/tX_engine.cc
src/tX_tape.cc
src/tX_tape.h
src/tX_vtt.cc
src/tX_vtt.h

index 9f47aeeedf727b5ab9638cc05a92509b79af2760..a740a37bdb9174003079dc03bf49794e009fd070 100644 (file)
@@ -87,6 +87,8 @@ int tX_audiodevice_oss :: open()
        p =  globals.oss_samplerate;
        i += ioctl(fd, SOUND_PCM_WRITE_RATE, &p);
        
+       sample_rate=globals.oss_samplerate;
+       
        /* Figure actual blocksize.. */
        
        i += ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &blocksize);
@@ -193,6 +195,8 @@ int tX_audiodevice_alsa :: open()
                tX_warning("ALSA: The PCM device \"%s\" doesnt support 44100 Hz playback - using %i instead", pcm_name, hw_rate);
        }       
 
+       sample_rate=hw_rate;
+       
        /* Using stereo output */
        if (snd_pcm_hw_params_set_channels(pcm_handle, hw_params, 2) < 0) {
                tX_error("ALSA: PCM device \"%s\" does not support stereo operation", pcm_name);
index 76f19294ac76f39442b0e077664d3341f75b0dd7..1d5c29156f481802678a521f38cf4dd991e6ed38 100644 (file)
@@ -41,11 +41,13 @@ class tX_audiodevice
 {
        protected:
        int samples_per_buffer;
+       int sample_rate;
        void init();
        
        public:
        virtual double get_latency()=0; /* call only valid *after* open() */
        int get_buffersize() { return samples_per_buffer; } /* call only valid *after* open() */
+       int get_sample_rate() { return sample_rate; }
        
        virtual int open()=0;
        virtual int close()=0;
index 06eb7d28dd3a54457c108cc9881faaef8bf34fe8..f7e09712d17dc6b44b66dda07e75c785f0d9d271 100644 (file)
@@ -255,10 +255,11 @@ tX_engine_error tX_engine :: run() {
                return ERROR_AUDIO;
        }       
 
+       vtt_class::set_sample_rate(device->get_sample_rate());
        vtt_class::set_mix_buffer_size(device->get_buffersize()/2); //mixbuffer is mono
        
        if (recording_request) {
-               if (tape->start_record(globals.record_filename, device->get_buffersize()*sizeof(int16_t))) {
+               if (tape->start_record(globals.record_filename, device->get_buffersize()*sizeof(int16_t), device->get_sample_rate())) {
                        device->close();
                        delete device;
                        device=NULL;                    
index b2ae62553ac1cbeccf6f94ae5d914c4118ba2d6c..a2bf6aa79f24a6e9ff9d2694a79d69b7c1f94b11 100644 (file)
@@ -31,15 +31,15 @@ tx_tapedeck :: tx_tapedeck()
        written_bytes=0;
 }
 
-int tx_tapedeck :: start_record (char *name, int bs)
+int tx_tapedeck :: start_record (char *name, int bs, int samplerate)
 {
        if (is_recording) return 1;
                
        strcpy(file.name, name);
-       file.srate=44100;
+       file.srate=samplerate;
        file.chans=2;
        file.depth=16;
-       file.bps=88200;
+       file.bps=samplerate*2;
        file.blkalign=2;
        file.len=0;
        file.sofar=0;
index 3b153134879031f9433ed3cb3d9625727e9d5fef..158bd4e6e2f082993ef4b882139f7b7379d6ff99 100644 (file)
@@ -35,7 +35,7 @@ class tx_tapedeck
        int blocksize;
        
        public:
-       int start_record(char *, int);
+       int start_record(char *name, int bs, int samplerate);
        void stop_record();
        void eat(int16_t *);
        
index 5d9c0d8946c6950c7024bd848a23cb11d105157a..40f3152f7118e4e4426602f3f68e7e52ebe141e2 100644 (file)
@@ -1990,3 +1990,18 @@ void vtt_class :: hide_control(bool hide) {
        control_hidden=hide;
        gui_hide_control_panel(this, hide);     
 }
+
+void vtt_class :: set_sample_rate(int samplerate) {
+       list <vtt_class *> :: iterator vtt;
+       double sr=(double) samplerate;
+       
+       for (vtt=main_list.begin(); vtt!=main_list.end() ; vtt++) {
+               if ((*vtt)->audiofile) {
+                       double file_rate=(*vtt)->audiofile->get_sample_rate();
+                       (*vtt)->audiofile_pitch_correction=file_rate/sr;
+               } else {
+                       (*vtt)->audiofile_pitch_correction=1.0;
+               }
+               (*vtt)->recalc_pitch();
+       }
+}
index 36575659762fe60252e461580e0962a9ad6ee3bc..f0a67a9fc06ebcc40a86d06c5ad3208eb6876648 100644 (file)
@@ -283,7 +283,8 @@ class vtt_class
        static void enable_saturate(int);
        static void focus_no(int);
        static void focus_next();
-       static void unfocus();  
+       static void unfocus();
+       static void set_sample_rate(int samplerate);
        int trigger();
        
        int stop();