comparison src/Modules/Input/ModuleFileInput.cc @ 135:0c492eada814

- Allow processing without re-initialization.
author tom@acousticscale.org
date Tue, 26 Oct 2010 04:48:56 +0000
parents 3cdaa81c3aca
children f8ace1ee8782
comparison
equal deleted inserted replaced
134:5d4b269b67d2 135:0c492eada814
50 file_handle_ = NULL; 50 file_handle_ = NULL;
51 } 51 }
52 } 52 }
53 53
54 void ModuleFileInput::ResetInternal() { 54 void ModuleFileInput::ResetInternal() {
55 // If there's a file open, rewind to the beginning.
56 if (file_handle_ != NULL) {
57 sf_seek(file_handle_, 0, SEEK_SET);
58 file_position_samples_ = 0;
59 }
60 }
61
62 bool ModuleFileInput::InitializeInternal(const SignalBank& input) {
63 // If there's a file open. Close it. 55 // If there's a file open. Close it.
64 if (file_handle_ != NULL) { 56 if (file_handle_ != NULL) {
65 sf_close(file_handle_); 57 sf_close(file_handle_);
66 file_handle_ = NULL; 58 file_handle_ = NULL;
67 } 59 }
68 // Open the file 60 // Open a file
69 SF_INFO sfinfo; 61 SF_INFO sfinfo;
70 memset(reinterpret_cast<void*>(&sfinfo), 0, sizeof(SF_INFO)); 62 memset(reinterpret_cast<void*>(&sfinfo), 0, sizeof(SF_INFO));
71 63
72 file_loaded_ = false; 64 file_loaded_ = false;
73 file_handle_ = sf_open(global_parameters_->GetString("input_filename"), 65 file_handle_ = sf_open(global_parameters_->GetString("input_filename"),
77 if (file_handle_ == NULL) { 69 if (file_handle_ == NULL) {
78 /*! \todo Also display error reason 70 /*! \todo Also display error reason
79 */ 71 */
80 LOG_ERROR(_T("Couldn't read audio file '%s'"), 72 LOG_ERROR(_T("Couldn't read audio file '%s'"),
81 global_parameters_->GetString("input_filename")); 73 global_parameters_->GetString("input_filename"));
82 return false; 74 return;
83 } 75 }
84 76
85 file_loaded_ = true; 77 file_loaded_ = true;
86 done_ = false; 78 done_ = false;
87 audio_channels_ = sfinfo.channels; 79 audio_channels_ = sfinfo.channels;
88 sample_rate_ = sfinfo.samplerate; 80 sample_rate_ = sfinfo.samplerate;
89 file_position_samples_ = 0; 81 file_position_samples_ = 0;
90 82
91 if (audio_channels_ < 1 || buffer_length_ < 1 || sample_rate_ < 0.0f) { 83 if (audio_channels_ < 1 || buffer_length_ < 1 || sample_rate_ < 0.0f) {
92 LOG_ERROR(_T("Problem with file: audio_channels = %d, buffer_length_ = %d, sample_rate = %f"), audio_channels_, buffer_length_, sample_rate_); 84 LOG_ERROR(_T("Problem with file: audio_channels = %d, buffer_length_ = %d, sample_rate = %f"), audio_channels_, buffer_length_, sample_rate_);
93 return false; 85 return;
94 } 86 }
95 87
96 output_.Initialize(audio_channels_, buffer_length_, sample_rate_); 88 output_.Initialize(audio_channels_, buffer_length_, sample_rate_);
97 output_.set_start_time(0); 89 output_.set_start_time(0);
98 90 }
91
92 bool ModuleFileInput::InitializeInternal(const SignalBank& input) {
93 ResetInternal();
99 return true; 94 return true;
100 } 95 }
101 96
102 void ModuleFileInput::Process(const SignalBank& input) { 97 void ModuleFileInput::Process(const SignalBank& input) {
103 if (!file_loaded_) 98 if (!file_loaded_)