| | |
| | | |
| | | int AudioFrame::Disp() |
| | | { |
| | | printf("not imp!!!!\n"); |
| | | |
| | | LOG(ERROR) << "Not imp!!!!"; |
| | | return 0; |
| | | }; |
| | | |
| | |
| | | |
| | | void Audio::Disp() |
| | | { |
| | | printf("Audio time is %f s. len is %d\n", (float)speech_len / MODEL_SAMPLE_RATE, |
| | | speech_len); |
| | | LOG(INFO) << "Audio time is " << (float)speech_len / MODEL_SAMPLE_RATE << " s. len is " << speech_len; |
| | | } |
| | | |
| | | float Audio::GetTimeLen() |
| | |
| | | void Audio::WavResample(int32_t sampling_rate, const float *waveform, |
| | | int32_t n) |
| | | { |
| | | printf( |
| | | "Creating a resampler:\n" |
| | | " in_sample_rate: %d\n" |
| | | " output_sample_rate: %d\n", |
| | | sampling_rate, static_cast<int32_t>(MODEL_SAMPLE_RATE)); |
| | | LOG(INFO) << "Creating a resampler:\n" |
| | | << " in_sample_rate: "<< sampling_rate << "\n" |
| | | << " output_sample_rate: " << static_cast<int32_t>(MODEL_SAMPLE_RATE); |
| | | float min_freq = |
| | | std::min<int32_t>(sampling_rate, MODEL_SAMPLE_RATE); |
| | | float lowpass_cutoff = 0.99 * 0.5 * min_freq; |
| | | |
| | | int32_t lowpass_filter_width = 6; |
| | | //FIXME |
| | | //auto resampler = new LinearResample( |
| | | // sampling_rate, model_sample_rate, lowpass_cutoff, lowpass_filter_width); |
| | | |
| | | auto resampler = std::make_unique<LinearResample>( |
| | | sampling_rate, MODEL_SAMPLE_RATE, lowpass_cutoff, lowpass_filter_width); |
| | | std::vector<float> samples; |
| | |
| | | std::ifstream is(filename, std::ifstream::binary); |
| | | is.read(reinterpret_cast<char *>(&header), sizeof(header)); |
| | | if(!is){ |
| | | fprintf(stderr, "Failed to read %s\n", filename); |
| | | LOG(ERROR) << "Failed to read " << filename; |
| | | return false; |
| | | } |
| | | |
| | |
| | | memset(speech_buff, 0, sizeof(int16_t) * speech_len); |
| | | is.read(reinterpret_cast<char *>(speech_buff), header.subchunk2_size); |
| | | if (!is) { |
| | | fprintf(stderr, "Failed to read %s\n", filename); |
| | | LOG(ERROR) << "Failed to read " << filename; |
| | | return false; |
| | | } |
| | | speech_data = (float*)malloc(sizeof(float) * speech_len); |
| | |
| | | FILE* fp; |
| | | fp = fopen(filename, "rb"); |
| | | if (fp == nullptr) |
| | | LOG(ERROR) << "Failed to read " << filename; |
| | | return false; |
| | | fseek(fp, 0, SEEK_END); |
| | | uint32_t n_file_len = ftell(fp); |