Python audio library for simultaneous audio creation and playback - c++

I'm working on an audio creation framework. It'll be generating large audio files, say 3 minute long audio files that take about 1 minute to generate. So what I want is a system much like streaming audio from the internet, where I play the sound as I generate it.
Pygame's mixer allows me to edit the sound as it's playing. But I cannot figure out how to change the sample rate, sample size, or number of channels.
Snack allows me to edit sounds, as well as their sample rate, sample size, length, and number of channels. But I cannot figure out how to edit sounds as they are playing.
Could anybody point me to a library that allows me to edit a sound as it is playing, as well as configure the number of channels, sample rate, and length (all known ahead of time)? If not, perhaps somebody knows of a tutorial to do this in C++?
[EDIT] Pymedia.audio would work fine for me. However, I can't get it to work under Python 2.6. Any ideas?

pymedia.audio does work with Python 2.6. Take a look at this SO post: Pymedia installation on Windows with Python 2.6
You can append audio to Output objects, as they are playing. So as each sample is generated, it can also be appended to the stream. The example in their documentation shows just how to do this: http://pymedia.org/docs/pymedia.audio.sound.html

Related

Is there a way to download a video at the playback rate (a rate that would simulate user watching it)?

So I know that one can adjust the rate of download with youtube-dl using the -r or --limit-rate flags; however, as part of a simulation testing, I am trying to simulate a user watching a video , and so I want to download a video at a rate such that the download would take as long as the video's duration is if one were to watch the video, so that a 2min long video would take 2min to download, and so on and so forth.
I have meticulously reviewed the available options on their github page, but it seems like there are no options natively to do that. But then the next best thing I can think of is to get the video duration in seconds (lets call it t) and the video size in bytes (lets call it s) and then use s/t as a value for the --limit-rate flag.
However now the problem is that there doesn't seem to be any options/flags to get the video file-size in bytes!
Is there anyway I can accomplish what my goal is here? I am open to using other tools/programs if this is outside the capabilities of youtube-dl.
To be more specific, I am working in linux server environment (no video-card and needs to be able headlessly), and the videos I'm dealing with are MPEG Dash videos from an MPD file, so whatever tool I use needs to be able to parse and work with MPD files.
Thank you for your help,

Convert frames to video on demand

I'm working on a c++ project that generates frames to be converted to a video later.
The project currently dumps all frames as jpg or png files in a folder and then I run ffmpeg manually to generate a mp4 video file.
This project runs on a web server and an ios/android app (under development) will call this web server to have the video generated and downloaded.
The web service is pretty much done and working fine.
I don't like this approach for obvious reasons like a server dependency, cost etc...
I successfully created a POC that exposes the frame generator lib to android and I got it to save the frames in a folder, my next step now is to convert it to video. I considered using any ffmpeg for android/ios lib and just call it when the frames are done.
Although it seems like I fixed half of the problem, I found a new one which is... each frame depending on the configuration could end up having 200kb+ in size, so depending on the amount of frames, it will take a lot of space from the user's device.
I'm sure this will become a huge problem very easily.
So I believe that the ideal solution would be to generate the mp4 file on demand as each frame is created, so in the end there would be no storage space being taken as I woudn't need to save a file for the frame.
The problem is that I don't know how to do that, I don't know much about ffmpeg, I know it's open source but I have no idea how to include a reference to it from the frames generator and generate the video "on demand".
I heard about libav as well but again, same problem...
I would really appreciate any sugestion on how to do it. What I need is basically a way to generate a mp4 video file given a list of frames.
thanks for any help!

C++ playing audio live from byte array

I am using C++ and have the sample rate, number of channels, and bit depth for my audio. I also have a char array containing the audio that I want to play. I am look for something along the lines of, sending a quarter of a second (or some other short amount of audio) to be played, then sending some more, etc. Is this possible, and if it is how would it be done.
Thanks for any help.
I've done this before with the library OpenAL.
This would require a pretty involved answer and hopefully the OpenAL documentation can walk you through it all, but here is the source example which I wrote that plays audio streaming in from a mumble server in nodejs.
You may need to ask a more specific question to get a better answer as this is a fairly large topic. It may also help to list other technologies you may be using such as target operating system(s) and if you are using any libraries already. Many desktop and game engines already have api's for playing simple sounds and using OpenAL may be much more complex than you really need.
But, briefly, the steps of the solution are:
Enumerate devices
Capture a device
Stream data to device
enqueue audio to buffer alSourceQueueBuffers
play queued buffer alSourcePlay

Using FMOD in C++ to create and playback sounds in realtime. (UE4)

Looking through all the API documentation, I can see how one could create procedural audio, but once an audio file is created, I want it to play on an object, but from I can tell, I believe I need it to play using the function calls PlayEventAtLocation in the UE4 plugin, which means I need to get the sound into an event.
I used to have my setup in Unity 4.x. I want to dynamically construct a wav file in game and play it back. The idea was to have silent audio all over the map that would loop, but play muted. The player when in range would capture audio from this muted audio source at their discretion.
The idea is that you have wav file that plays in game and at any given time I can start grabbing data from where the buffer is at currently until I decide to stop. I take all the data that I created in this new buffer and create a new wav file with it.
Example, like a 20 second file, but I would grab the a 7 second audio clip starting 5 seconds in. So my new audio file would be from 5 to 12. I would think you could do similar things in FMOD because I’ve looked at the recording examples and gapless playback examples, etc. and it does seem to have that same functionality and access to seek the files.
Now I need to migrate this new file that will made in game to something UE4 would use. In FMOD, looking through the .h and .cpp files in the plugin files, I see accept Fmod events only to attach to a UObject. Since I've not made an event in FMOD Studio, I can't use these. What is the sound that createSound makes? is it a wav? and fsb? I just a have a sound, and don't know what format it is.
I can’t use designer to make this sound because its dependent on the player at any given time during play.
In Unity, what I did was access the buffer of an audio file, pull data from the buffer for any given time, and place in a new buffer that I then turned into a file. While pulling data, I would check buffer size and frequency of sound files to make sure I had a gapless playback. (Not perfect, but pretty darn close), I’d use the audio functions in Unity to convert my array of data into a useable audioclip and run it through a sound emitter. It was pretty nice. Because I would keep the original wav file muted, but looping. So the player never knew what they captured. It was really nice.
Since UE4 doesn’t allow access to uncompressed PCM data, I can't do this low level data manipulation in UE4. I had to use FMOD, but its proving to be just as difficult because either its not documented, or lacks the functionality I want. I need help please.
If the data that is created in createsound is just normal pcm wav file data, then I can use a standard AudioComponent, and just save it to a file, and pull it in from UE4. If it is, then I need to turn it into an event so I can use FMODPlayEventAttached from the FMOD plugin library.
I've made a few other posts in various locations that have all been silent. Any comment would be appreciated. I know I've been reading a lot of documentation these last few days on FMOD, but I still may have missed something if people want to point me in a better direction, or if you have something to add, feel free.
Thanks all. I hope I was descriptive enough.

Changin mp3 speed in Qt and C++ [QMediaPlayer]

I'm trying to develop a little application in which you can load a mp3 file and play it in variable speeds! (I know it already exists :-) )
I'm using Qt and C++. I already have the basic player but I'm stuck with the rate thing, because I want to change the rate smoothly (like in Mixxx) without stopping the playback! The QMediaPlayer always stops if I change the value and creates a gap in the sound. Also I don't want the pitch to change!
I already found something called "SoundTouch" but now I'm completely clueless what to do with it, how to process my mp3 data and how to get it to the player! The "SoundTouch" Library is capable of doing what I want, i got that from the samples on the homepage.
How do I have to import the mp3 file, so I can process it with the SoundTouch functions
How can I play the output from the SoundTouch function? (Perhaps QMediaPlayer can do the job?)
How is that stuff done live? I have to do some kind of stream I guess? So I can change the speed during play and keep on playing without gaps. Graphicaly in my head it has to be something that sits between the data and the player, where all data has to go through live, with a small buffer (20-50 ms or so) behind to avoid gaps during processing future data.
Any help appreciated! I'm also open to any another solution then "SoundTouch" as long as I can stay with Qt/C++!
(Second thing: I want to view a waveform overview aswell as moving part of it (around actual position of the song), so I could also use hints on how to get the waveform data)
Thanks in advance!
As of now (Qt 5.5) this is impossible to do with QMediaPlayer only. You need to do the following:
Decode the audio using GStreamer, FFMpeg or (new) QAudioDecoder: http://doc.qt.io/qt-5/qaudiodecoder.html - this will give you raw PCM stream;
Apply SoundTouch or some other library to this raw data to change the pitch. If GPL is ok, take a look at http://nsound.sourceforge.net/examples/index.html, if you develop proprietary stuff, STK might be a better choice: https://ccrma.stanford.edu/software/stk/
Output the modified data into audio device by using QAudioOutput.
This strategy uses Qt as much as possible, and brings you the best platform coverage (you still lose Android though as it does not support QAudioOutput)