pcm

Correct way to Convert 16bit PCM Wave data to float

浪尽此生 提交于 2021-02-18 07:24:32
问题 I have a wave file in 16bit PCM form. I've got the raw data in a byte[] and a method for extracting samples, and I need them in float format, i.e. a float[] to do a Fourier Transform. Here's my code, does this look right? I'm working on Android so javax.sound.sampled etc. is not available. private static short getSample(byte[] buffer, int position) { return (short) (((buffer[position + 1] & 0xff) << 8) | (buffer[position] & 0xff)); } ... float[] samples = new float[samplesLength]; for (int i

Why does avcodec_fill_audio_frame return -22 when only sample count is different?

主宰稳场 提交于 2021-02-10 14:19:44
问题 My problem is very fast to explain: I have to encode audio samples using FFmpeg (raw PCM to G.711 mu-law). This is the guilty part of my code (I put raw parameters in this example to be explicit): AVFrame* frame = av_frame_alloc(); frame->nb_samples = 8000; frame->format = AV_SAMPLE_FMT_S16; frame->channels = 1; frame->channel_layout = AV_CH_LAYOUT_MONO; frame->sample_rate = 8000; frame->quality = 1; int res = avcodec_fill_audio_frame(frame, 1, AV_SAMPLE_FMT_S16, /*my samples data*/, 16000, 0

How can I read info from .wave file using JavaSound (Java, Java Sound)

自闭症网瘾萝莉.ら 提交于 2021-02-10 05:34:27
问题 Hi I need to read SampleRate, SignalFrequency and Amplitude from .wave file. How can I do that using JavaSound? 回答1: You can get the sampling rate by getting a handle on the AudioFormat object: AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("test.wav")); AudioFormat audioFormat = audioInputStream.getFormat(); Once you have that, you can get the sample rate as follows: float sampleRate = audioFormat.getSampleRate(); As for the amplitude, that is basically the raw

Schedule buffer with AVAudioPCMBuffer int16 data

那年仲夏 提交于 2021-01-29 14:58:04
问题 I'm trying to play music from byte array which is coming from the network in pcmInt16 data format. // formats let format1 = AVAudioFormat(commonFormat: AVAudioCommonFormat.pcmFormatFloat32, sampleRate: 48000, channels: 1, interleaved: false)! let format2 = AVAudioFormat(commonFormat: AVAudioCommonFormat.pcmFormatInt16, sampleRate: 48000, channels: 1, interleaved: false)! // byte array buffer var byteArray: [Int16]! // one packet size is 512 ... // 1. create / attach / connect engine engine

I need to convert audio file from μ-law to PCM

会有一股神秘感。 提交于 2021-01-28 10:21:51
问题 I need to convert wav file from FORMAT 1 to FORMAT 2 Format 1 : μ-law, 8000Hz, 64 kbps, mono FORMAT 2 : Container WAV Encoding PCM Rate 16K Sample Format 16 bit Channels Mono Following is the Code snippet : File file = new File("audio_before_conversion.wav"); AudioFormat audioFormat = new AudioFormat(16000, 16, 1, true , true); AudioInputStream audioInputStream1 = new AudioInputStream( new FileInputStream(file), audioFormat, numFrames); AudioSystem.write(audioInputStream1, Type.WAVE, new File

I need to convert audio file from μ-law to PCM

守給你的承諾、 提交于 2021-01-28 10:20:32
问题 I need to convert wav file from FORMAT 1 to FORMAT 2 Format 1 : μ-law, 8000Hz, 64 kbps, mono FORMAT 2 : Container WAV Encoding PCM Rate 16K Sample Format 16 bit Channels Mono Following is the Code snippet : File file = new File("audio_before_conversion.wav"); AudioFormat audioFormat = new AudioFormat(16000, 16, 1, true , true); AudioInputStream audioInputStream1 = new AudioInputStream( new FileInputStream(file), audioFormat, numFrames); AudioSystem.write(audioInputStream1, Type.WAVE, new File

I need to convert audio file from μ-law to PCM

痴心易碎 提交于 2021-01-28 10:18:27
问题 I need to convert wav file from FORMAT 1 to FORMAT 2 Format 1 : μ-law, 8000Hz, 64 kbps, mono FORMAT 2 : Container WAV Encoding PCM Rate 16K Sample Format 16 bit Channels Mono Following is the Code snippet : File file = new File("audio_before_conversion.wav"); AudioFormat audioFormat = new AudioFormat(16000, 16, 1, true , true); AudioInputStream audioInputStream1 = new AudioInputStream( new FileInputStream(file), audioFormat, numFrames); AudioSystem.write(audioInputStream1, Type.WAVE, new File

Updating/appending to a .wav file in Python

[亡魂溺海] 提交于 2021-01-28 05:23:02
问题 I have a stream of PCM audio frames coming into my Python script, and I am able to save blocks of these frames as .wav files as such: def update_wav(): filename = "test.wav" wav_file = wave.open(filename, "wb") n_frames = len(audio) wav_file.setparams((n_channels, sample_width, sample_rate, n_frames, comptype, compname)) for sample in audio: wav_file.writeframes(struct.pack('h', int(sample * 32767.0))) wav_file.close() However, I'd like this to continually update as new frames come in. Is

Mixing two16-bit encoded stereo PCM samples causing noise and distortion in the resulting audio

别等时光非礼了梦想. 提交于 2021-01-27 21:35:59
问题 I get two different audio samples from two sources. For microphone sound: audioRecord = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, 44100, AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT, (AudioRecord.getMinBufferSize(44100, AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT)*5)); For Internal sound: audioRecord = new AudioRecord.Builder() .setAudioPlaybackCaptureConfig(config) .setAudioFormat(new AudioFormat.Builder() .setEncoding(AudioFormat.ENCODING_PCM

How to insert silence pcm data when there is no data piping in

这一生的挚爱 提交于 2021-01-07 01:59:07
问题 I'm currently working on Discord.js voice receiver and I need it to continuously send PCM audio data by writing silent packet when there is no actual audio data coming in. I found this discussion before but I don't understand/know how to insert silent packets when there's no actual packet is coming in Receiver code: const r = connection.receiver.createStream(user, { mode: 'pcm', end: 'manual' }); // Nothing is piped when user is not talking // u.stream is PassThrough stream r.pipe(u.stream);