PyAudio Oversampling on Windows 10 - windows

I have written a program in Python which reads a stream of data from an external sound card. From my mac computer I can connect to the sound card at 44.1, 48, 96, 192 & 384 kHz without any issues, however on the Windows platform it is only possible to connect at 44.1 kHz., all other sample rates result in [errno -9997] Incorrect sample rate
Quick test with Audacity shows it is possible to connect to the device at higher sample rates.
Can anyone help me with this problem?
audio_format = pyaudio.paInt16
device_channels = devices[device]['maxInputChannels']
# Open the selected audio input device
stream = p.open(
format=audio_format,
channels=device_channels,
rate=sample_rate,
input=True,
output=False,
input_device_index=device,
frames_per_buffer=chunk_size)
On my mac the program works perfectly at all sample rates but it behaves differently on windows.

Related

reading from rtsp stream on mac os x using popen and read is failing

I am generating an rtsp stream using gstreamer in an iOS app and trying to use ffmpeg in a Mac OS X audio driver that I wrote using XCode to strip the audio out of the stream and then pump the audio to Skype or Zoom or whatever. All the code is written in the 'C' old-fashioned programming language. I do get a FILE* that is not NULL back from a popen function call to execute ffmpeg on the input rtsp stream. But once I get that FILE* object and try to read binary data from it, it returns that zero bytes have been read. Here is the code:
FILE *readPipeFromFFMPEG = popen("Contents/MacOS/ffmpeg -i rtsp://192.168.0.30:8554/test -vn -acodec copy -flush_packets pipe:1", "r+");
int pipeFD = fileno(readPipeFromFFMPEG);
char *buffer = (char*)calloc(inIOBufferFrameSize * 8, 1);
numBytesRead = read(pipeFD, buffer, inIOBufferFrameSize * 8);
free(buffer);
pclose(readPipeFromFFMPEG);
but numBytesRead is always coming back as zero. Does anybody have any clue what I need to do to get this working properly? It seems like maybe a permissions issue where I do not have permission to read from the stream? Or maybe my ffmpeg parameters are incorrect? I am able to open up the stream in VLC and OBS Studio no problem and it displays the video frames and plays the audio. I am really stuck I need help! I must be missing something totally obvious because when I run OBS Studio or VLC it shows in the iPhone app the requests from the client because it prints out information that the audio and video packets are being requested but when the audio driver is running nothing is printed out in the iPhone app.

Real time microphone audio manipulation windows

I would like to make an app (Target pc windows) that let you modify the micro input in real time, like introducing sound effects or even modulating your voice.
I searched over the internet and only found people telling that it would not be possible without using a virtual audio cable.
However I know some apps with similar behavior (voicemod, resonance) not using a virtual audio cable so I would like some help about how can be done (just the name of a library capable would be enough) or where to start.
Firstly, you can use professional ready-made software for that - Digital audio workstation (DAW) in combination with a huge number of plugins for that.
See 5 steps to real-time process your instrument in the DAW.
And What is (audio) direct monitoring?
If you are sure you have to write your own, you can use libraries for real-time audio processing (as far as I know, C++ is better for this than C#).
These libraries really works. They are specially designed for realtime.
https://github.com/thestk/rtaudio
http://www.portaudio.com/
See also https://en.wikipedia.org/wiki/Csound
If you don't have a professional sound interface yet, but want to minimize a latency, read about Asio4All
The linked tutorial worked for me. In it, a sound is recorded and saved to a .wav.
The key to having this stream to a speaker would be opening a SourceDataLine and outputting to that instead of writing to a wav file. So, instead of outputting on line 59 to AudioSystem.write, output to a SourceDataLine write method.
IDK if there will be a feedback issue. Probably good to output to headphones and not your speakers!
To add an effect, the AudioInputLine has to be accessed and processed in segments. In each segment the following needs to happen:
obtain the byte array from the AudioInputLine
convert the audio bytes to PCM
apply your audio effect to the PCM (if the effect is a volume change over time, this could be done by progressively altering a volume factor between 0 to 1, multiplying the factor against the PCM)
convert back to audio bytes
write to the SourceDataLine
All these steps have been covered in StackOverflow posts.
The link tutorial does some simplification in how file locations, threads, and the stopping and starting are handled. But most importantly, it shows a working, live audio line from the microphone.

How to interpret Apple Core Media Frame Quanta numbers?

The Apple Mac OS framework offers an api called CMTimeCodeFormatDescriptionGetFrameQuanta.
I'm trying to use this in a Swift Mac program's user interface as part of a pick list of video formats available from webcams and other video sources. It returns an integer. The doc says this about the units of its result.
Returns the frames/sec for timecode (e.g. 30) OR frames/tick for counter mode.
How do I make sense of frames/tick? The built in iSight camera gives back 0, 1932, or 35632, depending on the resolution of the format. A Logitec USB cam gives back mostly 73600, but sometimes 0 or 1932, also depending on resolution.
What does this number mean? How can I render it in a way that makes sense to end users, like 30fps or 24fps?

ffmpeg and 7160 HD Capture card error, already set rtbufsize 2000M, still real time buffer too full

The 7160 Capture card original video was shown fine in the Honestech HD DVR software that is included.
However, when the card was captured using ffmpeg and publish out. This error occurred after a while running ffmpeg:
real-time buffer [7160 HD Capture] video input too full or near too full ...
I have already set -rtbufsize 2000M which is nearly the maximum that is allowed and can not be increased further.
Please tell me how to resolve this bug or give me an example that can be used without producing this bug. Thank you very much. You do not neeed the code that I used because almost any code even the simplest code I used produced this error after running for a while. The published video also lag and lost.

Error while saving captured audio using AVAssetWriterInput

We are developing an audio recording application for 10.7.5 and above.
We are using AVCaptureAudioDataOutput to capture audio and data is written using AVAssetWriterInput.
Properties set to the AVAssetWriterInput as below:
AVFormatIDKey : kAudioFormatMPEG4AAC
AVSampleRateKey : This values is taken from device using below code
AudioStreamBasicDescription streanDesc;
UInt32 propSize = sizeof(AudioStreamBasicDescription);
AudioDeviceGetProperty(mInputDevice, 0, YES, kAudioDevicePropertyStreamFormat, &propSize,&streanDesc);
AVNumberOfChannelsKey : This is taken from AudioStreamBasicDescription.
AVEncoderBitRateKey : This is hardcoded to 96000.
This works fine for most of the audio device except for USB mic of sample rate 32khz and iSight device with sample rate 48khz.
When we use these two devices as input audio device, while writing audio data we are getting the following error -
Error Domain=AVFoundationErrorDomain Code=-11821 "Cannot Decode" UserInfo=0x279470 {NSLocalizedFailureReason=The media data could not be decoded. It may be damaged., NSUnderlyingError=0x292370 "The operation couldn’t be completed. (OSStatus error 560226676.)", NSLocalizedDescription=Cannot Decode}".
However in case of USB mic if we hardcode the AVSampleRateKey to 44100 it works perfectly fine but does not work for iSight device.
What is correct value to be provided for AVSampleRateKey? Can any one help me to resolve this issue.

Resources