I hear crackling sound when using 32bit integer numpy arrays to play audio
See original GitHub issueCode to reproduce the issue:
import numpy as np
import sounddevice as sd
frequency = 1000
sample_rate = 44100
duration = 2 # seconds
num_frames = int(duration*sample_rate)
t = np.arange(num_frames) / sample_rate
max_amp = 2**31-1 # maximum value of signed int32
signal = max_amp*np.sin(2 * np.pi * frequency * t)
signal = signal.astype(np.int32)
sd.play(signal,samplerate=sample_rate)
Current OS: Windows 10 Things I have tried:
- Running in other high end laptop running windows 10
- Directly using float32 format doesn’t cause crackling sound but I need to work with int32 and int24
- Using raw output stream and writing to audio buffer has same effect for int32 and int24
- int16 and int8 play well using same method
- float32 and float16 work well
- int24 has same issue as int32
- Increasing sampling rate from 44.1k to 96k increased the frequency of noise
- Disable enhancements in windows sound driver does nothing
- Uninstalled sound driver - no difference
- Tried giving stereo output with same results
- increasing block size upto 10 times the sample rate
- playing with latency settings
- Checking status of stream - no warning or error
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
howto stream numpy array into pyaudio stream?
My question is, can I stream a numpy array (or a regular list) directly into my the pyaudio to play? python · audio...
Read more >Untitled
#2015 Pileopsis, Freaks and geeks music episode 8, Lemon pipers blueberry blue ... Clarks wallabee run, Nu finish polish for boats, Practice sentences...
Read more >Changelog — PsychoPy v2022.2.4
JS: audio playback can fade in/out to avoid clicks. JS: Builder loops (TrialHandlers) support and update properties such as thisN as in Python...
Read more >Bug listing with status RESOLVED with resolution UPSTREAM ...
... Bug:25698 - "Sound playback in SDL through ALSA >= 0.9.2 on VIA 8233A ... I listen audio files" status:RESOLVED resolution:UPSTREAM severity:major ...
Read more >CircuitPython Documentation - Read the Docs
(for example, SuperDuperPython) and not use the Blinka logo. ... with native modules for tasks that require it such as audio file playback....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If there are multiple host APIs, your physical devices will appear multiple times in the device list. Each entry contains the host API name after the device name.
So by selecting a specific device from the list, you automatically select a host API at the same time.
Yeah, I think that’s not mentioned explicitly.
Do you have an idea how and where we could document this? Would you like to make a documentation PR for this?
What is the reason for that you say that you need to work with
int32
(your original data / processing generates that)?In any case, you should be able use
.astype(np.float32)
(and potentially scale the amplitude) to make it work, right?