From b9658af1276a01d9e8129db617fcdc74fb5b11df Mon Sep 17 00:00:00 2001 From: terminatorX <> Date: Sun, 23 Mar 2003 23:23:43 +0000 Subject: [PATCH] Consistent samplerate handling for playback and recording - Alex --- src/tX_audiodevice.cc | 4 ++++ src/tX_audiodevice.h | 2 ++ src/tX_engine.cc | 3 ++- src/tX_tape.cc | 6 +++--- src/tX_tape.h | 2 +- src/tX_vtt.cc | 15 +++++++++++++++ src/tX_vtt.h | 3 ++- 7 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/tX_audiodevice.cc b/src/tX_audiodevice.cc index 9f47aee..a740a37 100644 --- a/src/tX_audiodevice.cc +++ b/src/tX_audiodevice.cc @@ -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); diff --git a/src/tX_audiodevice.h b/src/tX_audiodevice.h index 76f1929..1d5c291 100644 --- a/src/tX_audiodevice.h +++ b/src/tX_audiodevice.h @@ -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; diff --git a/src/tX_engine.cc b/src/tX_engine.cc index 06eb7d2..f7e0971 100644 --- a/src/tX_engine.cc +++ b/src/tX_engine.cc @@ -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; diff --git a/src/tX_tape.cc b/src/tX_tape.cc index b2ae625..a2bf6aa 100644 --- a/src/tX_tape.cc +++ b/src/tX_tape.cc @@ -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; diff --git a/src/tX_tape.h b/src/tX_tape.h index 3b15313..158bd4e 100644 --- a/src/tX_tape.h +++ b/src/tX_tape.h @@ -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 *); diff --git a/src/tX_vtt.cc b/src/tX_vtt.cc index 5d9c0d8..40f3152 100644 --- a/src/tX_vtt.cc +++ b/src/tX_vtt.cc @@ -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 :: 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(); + } +} diff --git a/src/tX_vtt.h b/src/tX_vtt.h index 3657565..f0a67a9 100644 --- a/src/tX_vtt.h +++ b/src/tX_vtt.h @@ -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(); -- 2.30.2