| | |
| | | if (speech_data != NULL) { |
| | | free(speech_data); |
| | | } |
| | | if (speech_buff != NULL) { |
| | | free(speech_buff); |
| | | } |
| | | if (speech_char != NULL) { |
| | | free(speech_char); |
| | | } |
| | |
| | | memset(speech_data, 0, sizeof(float) * speech_len); |
| | | float scale = 1; |
| | | if (data_type == 1) { |
| | | scale = 32768; |
| | | scale = 32768.0f; |
| | | } |
| | | for (int32_t i = 0; i < speech_len; ++i) { |
| | | int16_t val = (int16_t)((resampled_buffers[2 * i + 1] << 8) | resampled_buffers[2 * i]); |
| | |
| | | if (speech_data != NULL) { |
| | | free(speech_data); |
| | | } |
| | | if (speech_buff != NULL) { |
| | | free(speech_buff); |
| | | } |
| | | offset = 0; |
| | | |
| | | speech_len = (resampled_buffers.size()) / 2; |
| | | speech_data = (float*)malloc(sizeof(float) * speech_len); |
| | |
| | | memset(speech_data, 0, sizeof(float) * speech_len); |
| | | float scale = 1; |
| | | if (data_type == 1) { |
| | | scale = 32768; |
| | | scale = 32768.0f; |
| | | } |
| | | for (int32_t i = 0; i < speech_len; ++i) { |
| | | int16_t val = (int16_t)((resampled_buffers[2 * i + 1] << 8) | resampled_buffers[2 * i]); |
| | |
| | | if (speech_buff != NULL) { |
| | | free(speech_buff); |
| | | } |
| | | offset = 0; |
| | | |
| | | std::memcpy(&header, buf, sizeof(header)); |
| | | |
| | |
| | | if (speech_data != NULL) { |
| | | free(speech_data); |
| | | } |
| | | if (speech_buff != NULL) { |
| | | free(speech_buff); |
| | | } |
| | | offset = 0; |
| | | |
| | | speech_len = n_buf_len / 2; |
| | | speech_buff = (int16_t*)malloc(sizeof(int16_t) * speech_len); |
| | | if (speech_buff) |
| | | { |
| | | memset(speech_buff, 0, sizeof(int16_t) * speech_len); |
| | | memcpy((void*)speech_buff, (const void*)buf, speech_len * sizeof(int16_t)); |
| | | |
| | | speech_data = (float*)malloc(sizeof(float) * speech_len); |
| | | memset(speech_data, 0, sizeof(float) * speech_len); |
| | | |
| | | speech_data = (float*)malloc(sizeof(float) * speech_len); |
| | | if(speech_data){ |
| | | float scale = 1; |
| | | if (data_type == 1) { |
| | | scale = 32768; |
| | | scale = 32768.0f; |
| | | } |
| | | const uint8_t* byte_buf = reinterpret_cast<const uint8_t*>(buf); |
| | | for (int32_t i = 0; i < speech_len; ++i) { |
| | | int16_t val = (int16_t)((byte_buf[2 * i + 1] << 8) | byte_buf[2 * i]); |
| | | speech_data[i] = (float)val / scale; |
| | | } |
| | | |
| | | for (int32_t i = 0; i != speech_len; ++i) { |
| | | speech_data[i] = (float)speech_buff[i] / scale; |
| | | } |
| | | |
| | | //resample |
| | | if(*sampling_rate != dest_sample_rate){ |
| | | WavResample(*sampling_rate, speech_data, speech_len); |
| | |
| | | |
| | | AudioFrame* frame = new AudioFrame(speech_len); |
| | | frame_queue.push(frame); |
| | | |
| | | return true; |
| | | |
| | | } |
| | | else |
| | | }else{ |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | bool Audio::LoadPcmwavOnline(const char* buf, int n_buf_len, int32_t* sampling_rate) |
| | |
| | | if (speech_data != NULL) { |
| | | free(speech_data); |
| | | } |
| | | if (speech_buff != NULL) { |
| | | free(speech_buff); |
| | | } |
| | | if (speech_char != NULL) { |
| | | free(speech_char); |
| | | } |
| | | |
| | | speech_len = n_buf_len / 2; |
| | | speech_buff = (int16_t*)malloc(sizeof(int16_t) * speech_len); |
| | | if (speech_buff) |
| | | { |
| | | memset(speech_buff, 0, sizeof(int16_t) * speech_len); |
| | | memcpy((void*)speech_buff, (const void*)buf, speech_len * sizeof(int16_t)); |
| | | |
| | | speech_data = (float*)malloc(sizeof(float) * speech_len); |
| | | memset(speech_data, 0, sizeof(float) * speech_len); |
| | | |
| | | speech_data = (float*)malloc(sizeof(float) * speech_len); |
| | | if(speech_data){ |
| | | float scale = 1; |
| | | if (data_type == 1) { |
| | | scale = 32768; |
| | | scale = 32768.0f; |
| | | } |
| | | const uint8_t* byte_buf = reinterpret_cast<const uint8_t*>(buf); |
| | | for (int32_t i = 0; i < speech_len; ++i) { |
| | | int16_t val = (int16_t)((byte_buf[2 * i + 1] << 8) | byte_buf[2 * i]); |
| | | speech_data[i] = (float)val / scale; |
| | | } |
| | | |
| | | for (int32_t i = 0; i != speech_len; ++i) { |
| | | speech_data[i] = (float)speech_buff[i] / scale; |
| | | } |
| | | |
| | | //resample |
| | | if(*sampling_rate != dest_sample_rate){ |
| | | WavResample(*sampling_rate, speech_data, speech_len); |
| | |
| | | |
| | | AudioFrame* frame = new AudioFrame(speech_len); |
| | | frame_queue.push(frame); |
| | | |
| | | return true; |
| | | |
| | | } |
| | | else |
| | | }else{ |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | bool Audio::LoadPcmwav(const char* filename, int32_t* sampling_rate, bool resample) |