How to change the sample rate in jack audio? - audio

I'm a relative beginner at audio, so please forgive me if there is an obvious answer to this question! I've been trying to change the sample rate from 44100 to 11025 Hz in jack audio (I'm using a Scarlet 4i4 3rd generation).
I'm trying to change it within a script in C (I know you can do it on command line or with qjackctl), so I was wondering if a) there was a simple way to do this with jack_client_open (the input parameters from what I understand don't seem to provide an option for sample rate but as a beginner I would not be surprised if I'm completely mistaken :)) or b) if there was a way to use something like system to call a command line prompt within C code but that would output the "client" that is created/opened so that I could utilize it further down in the function. Thank you so much in advance!

As far as I know, you can't change the samplerate from your Jack client. The samplerate is defined in the Jack server and your client uses this samplerate.
You can't change it on the fly. For example, if you change the samplerate from QjackCtl you will have to restart your Jack server to make it effective.
I guess you could use a system call from your application to start the Jack server with the desired samplerate, but again it will not "output the client". It will launch the Jack server which you can then connect your app.

Related

Sending a webcam input to zoom using a recorded clip

I have an idea that I have been working on, but there are some technical details that I would love to understand before I proceed.
From what I understand, Linux communicates with the underlying hardware through the /dev/. I was messing around with my video cam input to zoom and I found someone explaining that I need to create a virtual device and mount it to the output of another program called v4loop.
My questions are
1- How does Zoom detect the webcams available for input. My /dev directory has 2 "files" called video (/dev/video0 and /dev/video1), yet zoom only detects one webcam. Is the webcam communication done through this video file or not? If yes, why does simply creating one doesn't affect Zoom input choices. If not, how does zoom detect the input and read the webcam feed?
2- can I create a virtual device and write a kernel module for it that feeds the input from a local file. I have written a lot of kernel modules, and I know they have a read, write, release methods. I want to parse the video whenever a read request from zoom is issued. How should the video be encoded? Is it an mp4 or a raw format or something else? How fast should I be sending input (in terms of kilobytes). I think it is a function of my webcam recording specs. If it is 1920x1080, and each pixel is 3 bytes (RGB), and it is recording at 20 fps, I can simply calculate how many bytes are generated per second, but how does Zoom expect the input to be Fed into it. Assuming that it is sending the strean in real time, then it should be reading input every few milliseconds. How do I get access to such information?
Thank you in advance. This is a learning experiment, I am just trying to do something fun that I am motivated to do, while learning more about Linux-hardware communication. I am still a beginner, so please go easy on me.
Apparently, there are two types of /dev/video* files. One for the metadata and the other is for the actual stream from the webcam. Creating a virtual device of the same type as the stream in the /dev directory did result in Zoom recognizing it as an independent webcam, even without creating its metadata file. I did finally achieve what I wanted, but I used OBS Studio virtual camera feature that was added after update 26.0.1, and it is working perfectly so far.

Intercepting Sound From Other Programs

I want to do a couple of things:
-I want to hear sound from all other programs through max, and max only.
-I want to edit that sound in real time and hear only the edited sound.
-I want to slow down the sound, while stacking the non-slowed, incoming input onto a buffer, which I can then speed through to catch up.
Is this possible in Max? I have had a lot of difficulty working even step 1. Even if I use my speakers as an input device, I am unable to monitor it let alone edit it. I am using Max for Live, for what it's worth.
Step 1 and 2
On Mac, you can use Loopback
You can set your system output to the loopback driver, then set the loopback driver as the input in Max and then the speakers as the output.
For Windows you would do the same, but with a different internal audio routing system like Jack
Step 3
You can do that with the buffer~ object. Of course the buffer will have a finite size, and storing hours of audio might be problematic, but minutes shouldn't be a problem on a decent computer. The buffer~ help file will show you the first steps needed to store and read audio from it.

Recording wav file Using Arduino

I am bit stuck, how can I make my arduino record into .wav files?
The arduino is connected with a microphone, and am using the Arduino ADC.
Any ideas? Will I be able to play them back using my pc?
many question cross my head
1- Is this possible using an arduino Uno
2- Is this possile using just a microphone connected to the Arduino ADC
3- if yes how can i get the wav format.
The idea gonna be like this
Ardiuno microphone-->Uno ADC -->arduino (library making wav sound)--> Storing data to a an SD card connected via SPI or maybe (connecting a Raspberry as a storage device)
also another question:
4- Do I need an amplifier due to the act that analog output from the microphone is very weak so the ADC couldn't detect the variation
In another log i had seen that i should connect the microphone to a level shifter.And that cause of the analog output is AC so i have to make the negative wave as 0 (for 10 it ADC)
the zero point as 512 and the positive as 1024 (10 bit ADC).(really i'm not sure about this part)
doing some research i got this library "https://github.com/TMRh20/TMRpcm/wiki/Advanced-Features#recording-audio" which is supposed to do the job, I mean making some wav file from the analog input.
So any help would be appreciated
Thx in advance,
Salah Laaroussi
Yes, although a bit complex it is very possible to do this via an uno.
The biggest hurdles to overcome is the limited amount of RAM and the clock speed. You will have to setup twin buffers to handle writing to the SD card. Make sure the card has a high enough write speed or the entire program will come to a screeching halt as you will run out of memory.
apc mag has a great article detailing out the circuit and code.
http://apcmag.com/arduino-projects-digital-audio-recorder.htm/
There are many things you haven't prepared yet:
output of microphone (assuming you know about electronics: still requires a biasing circuit e.g. a resistor + capacitor).
the output of the microphone is still very weak (in the magnitude of mV), which Arduino is incapable of capturing so you need a pre-amplifier
the design of the pre-amplifier will also include DC offset which makes the output of the microphone all above 0VDC which is in the range of the Arduino ADC otherwise the arduino will capture only those above 0VDC.

Streaming audio from avconv via NodeJs WebSockets into Chrome with AudioContext

we're having trouble playing streamed audio in a browser (using Chrome).
We have a process which is streaming some audio (for example an internet radio) on udp on some port. It's avconv (avconv -y -i SOMEURL -f alaw udp://localhost:PORT).
We have a NodeJs server which receives this audio stream and forwards it to multiple clients connected via websockets. The audio stream which NodeJs receives is wrapped in a buffer which is an array with numbers from 0 to 255. The data is sent to the browser without any issues and then we're using AudioContext to play the audio stream in the browser (our code is based on AudioStreamer - https://github.com/agektmr/AudioStreamer).
At first, all all we got at this point was static. When looking into the AudioStreamer code, we realized that the audio stream data should be in the -1 to 1 range. With this knowledge we tried modifying each value in the buffer with this formula x = (x/128) - 1. We did it just to see what would happen and surprisingly the static became a bit less awful - you could even make out melodies of songs or words if the audio was speech. But it's still very very bad, lots of static, so this is obviously not a solution - but it does show that we are indeed receiving the audio stream via the websockets and not just some random data.
So the question is - what are we doing wrong? Is there a codec/format we should be using? Of course all the code (the avconv, NodeJs and client side) can be modified at will. We could also use another browser if needed, though I assume that's not the problem here. The only thing we do know is that we really need this to work through websockets.
The OS running the avconv and NodeJs is Ubuntu (various versions 10-13)
Any ideas? All help will be appreciated.
Thanks!
Tomas
The conversion from integer samples to floating point samples is incorrect. You must take into account:
Number of channels
Number of bits per sample
Signed/unsigned
Endianess
Let's assume you have a typical WAV file at 16 bit stereo, signed, little-endian. You're on the right track with your formula, but try this:
x = (x/32768) - 1

play audio file over VoIP

I want to implement a simple VoIP system which can achieve following;
The user uploads a mp3 or wav file and gives a phone number.
the given phone number is dialed, when the phone is picked, the uploaded mp3/wav file is played. once the whole file is played, the call is hung up.
i want to know if there is any opensource library which supports this?? or an opensource software using which i can achieve this?
I do similar testing as this for my job.
I have
a test framework on my box in my office using Freeswitch and I've created some users with passwords on the FreeSWITCH box.
Then I use a sip testing tool / client to manage the connection to the sip proxy, to another user.
For example... say my freeswitch is ip: 120.0.0.7
I am registering on that freeswitch as user 5000 and i want to call user 4000 who is also registered.
I use either SIPP (linux) or SIPCLI (windows.)
SIPP
The benefits of SIPP is that it's truly robust and can do a myriad of performance testing, and what not. But ot send audio it's a bit challenging, but it's doable. you're basically sending pcap's of recorded audio in some codec (g711, g729, etc.) so you run a command like:
sudo sipp -s [the phone number/ user] [your freeswitch] -sn uac_pcap -mi [your ip] -l 1 -m 1
The last two parameters (l and m) set how much load, by default sipp will send 10calls per sec. you prob dont want that. so l says "limit the calls to #" and m says "only run x calls at a time."
SIPCLI
The much easier method is sipcli (but it's a windows only tool.)
In sipcli, you basically can send a wav file, as well as text to speech. I love it. it has a built in library that will dial the number and you could pass something like -t "This is a test of the test harness for sip and v o i p testing." it would convert that to audio on the call, on the fly. you can also build out scenarios that point to wav files you've recorded....
SIPCLI would use a command like SIPP to connect:
sipcli [user/phone number] -d [domain or proxy] -t "This is text i want converted to speech on the phone call"
you could also pass in a link to a wav.
sipcli can also send dtmf tones, or you could point to wav's of dtmf tones.
the scenario editor is a bit complex at first, and takes a bit of getting used to. But once you get the hang of making scenario files, it's pretty easy.
Benefits of SIPP
SIPP can capture performance metrics (the over all time in ms between your configured start and end point)
SIPP can drive thousands of calls at your desired end
SIPP can ramp up calls or ramp them down on the fly
SIPP can generate statisics and csv files for analysis
SIPP scenarios you write are building the packets themselves. So you have more control over what your packet sends on the INVITE.
SIPP is open source
Negatives of SIPP
SIPP can NOT send a wav file
SIPP can NOT generate it's own dtmf tones (it uses pcaps, which can be problematic)
SIPP can NOT generate text to speech
SIPP is somewhat complicated to get going
Benefits of SIPCLI
SIPCLI can convert text to speech on the fly
SIPCLI can use recorded wav's to send to the recipient
SIPCLI is easy to use
SIPCLI can also act as a reciever (i.e. an IVR playing a greeting and taking input)
SIPCLI has some logic to validate data received (like user pressed #3, then #4.)
Negatives of SIPCLI
SIPCLI doesn't let you have access to the SIP headers it sends (so less control over the test)
SIPCLI doesn't do load or performance metrics
SIPCLI's editor is kinda difficult at first, but it's not as hard as learning SIPP's advanced features
SIPCLI is NOT opensource.... it's trial is 90% useful. To get the other 10% (longer phone calls) you need to purchase it at $70.
I've also tried other tools like PJSua, but these two are my bread and butter for testing the scenarios you are talking about.
Regarding the Framework/softwsitch/proxy... I use Freeswitch.
Yes You can use Asterisk, Freeswitch ( My personal preference) Or a number of other platforms similar to this.
Once you have freeswitch setup, check out this link to get it going:
http://wiki.freeswitch.org/wiki/Javascript_QuickStart
use ivrworx for simple testing
see streamer example.

Resources