What is the Microsoft-approved way to extract the raw audio data from an audio CD? I'm hoping to do this with C++ or C.
It's ironic because in XP/Vista/7, there is the IMAPI (Image Mastering API) for writing data, but not for reading it.
Is there a set of API functions for this? Or do I need to send SCSI commands?
Here are a couple of code samples...
http://www.codeproject.com/KB/audio-video/SimpleAudioCD.aspx
http://www.codeproject.com/KB/cs/csharpripper.aspx
I would use open source for this. Have you looked at the CDEX project? The CDRip.dll in this project may be useful.
The windows audio guy, Larry Osterman, did a whole series about CD Audio playback on his blog (DAE,MCI)
Related
I have a question about playing .wav files in C++. I search for a method to play it on Linux and Windows and I want to break up it while a function has been ended, did you know a sample for this?
Thanks for any Answer :)!
I am from Germany, please don't be angry about my grammar or spelling :D.
There are several ways to do this.
The simplest, ugliest and most hackish way to do this is to write directly to your sound device located in /dev/snd/. However this really depends on your linux distribution and some modern ones no longer allows you to do this. In general, direct read / write to /dev/ devices is fading away. Here is a question answering this.
For a very long time, the "official" way was to use alsa library which uses a C style interface. It is usually pretty tricky, full of pitfalls and "workarounds" that depends on your exact audio hardware.
I think that alsa is getting gradually replaced by jack, which I hope is easier to use. I don't have any experience with this one.
The last method I know is with portaudio, which as the name implies, is somewhat portable between at least windows, linux and osx.
All of these library will allow you to control your audio hardware, init / setup / play. What is simple about wav files is that the content is raw pcm, which is usually the format used by those libraries. The wav format is usually like this :
[wav header] [audio data until the end of the file]
If you can manage a few milliseconds of garbage when you start playing, you can "safely" send the header for playback as well and avoid parsing it. You will have to understand PCM formats however and should bring some additional readings.
As an added "trick" which doesn't directly concern C++, I strongly suggest using Audacity. It is a small program which I see like the notepad / vim of audio files. It is small, it loads fast, allows you to copy / paste segments of audio and detect pcm formats. (Actually, you just change pcm settings until the audio "sounds" right, but still useful)
The title mentioned Linux, but then you mentioned Windows and Linux in the post.
For Linux, best is to use gstreamer if you insist on C++. Look through the gstreamer code for gst-launch. It is run as below in a Linux machine.
$ gst-launch filesrc location="location of file" ! wavparse ! alsasink
From, http://sanchayanmaity.github.io/beagleboard-xm/linux/programming/software/2014/08/07/playing-wavmp3-file-using-gstreamer-in-code.html
For windows, or if you want to use OS agnostic code on both Windows and Linux, you can use SDL,
http://lazyfoo.net/SDL_tutorials/lesson11/
Another alternative (cross-platform, Object oriented), is SFML. Check the audio wav file playback example at,
http://www.sfml-dev.org/tutorials/2.0/audio-sounds.php
I'm a reasonably advanced C++ programmer, as a bit of background. At this point, I'm wanting to experiment a bit with sound. Rather than use a library to load and play files, I'm wanting to figure out how to actually do that myself, for the understanding. For this application, I would like to read in a .wav file (I already have that part down), then output that data to the speakers. How do I push a waveform or the data from the file to the speakers on my computer? I'm on Windows, by the way.
You can read this article about how to set up the audio device and how to stream data into the device for playback on Windows. If using this library is too high-level for you and you'd like to go deeper and write your own decoding of WAV files and outputting that to a sound card, you have far more research to do than what's appropriate for an answer here.
Windows has so many APIs on this it is ridiculous. Supposedly MediaFoundation is the way to do this, but I see a lot of 'deprecated' in the MSDN documentation and the sample they provide is only for playing music from a URL. I have a compressed audio file in memory (mp3, m4a, etc). Right now I'm using their CPlayer example. ( https://msdn.microsoft.com/en-us/library/windows/desktop/bb970516(v=vs.85).aspx ).
Is there a way to have MediaFoundation load a source from memory? Or do I have to decompress it in a separate thread and feed it into XAudio2?
Yes, it is possible with Media Foundation thanks to the IMFMediaSource interface.
There is an article about this topic on MSDN : Writing a Custom Media Source
Regards,
We have a requirement to lets users record a video of our 3D application. I can already grab the individual rendered frames so this question is specifically about how to write frames into a video file.
I don't think writing each frame as a separate file and post-processing is a workable option.
I can look at options to record to a simple video file for later optimising/encoding, or writing directly to a sensibly encoded format.
FFmpeg was suggested in another post but it looks a bit daunting to me. Is it the best option, if not what can be suggested? We can work with LGPL but not full GPL.
We're working on Windows (Win32 not MFC) in C++. Sample/pseudo code with your recommended library is very much appreciated... basically after how to do 3 functions:
startRecording() does whatever initialization is needed
recordFrame() takes pointer to frame data and encodes it, ideally with timing data
endRecording() finalizes the video file, shuts down video system, etc
Check out the sources to Taksi on sourceforge. http://taksi.sourceforge.net/
You need 2 things.
1. A code to compress the frames.
2. A container file format. Like AVI or MPG.
Taksi useses the old VideoForWindows API and AVI not the newer COM API's but it still might work for you.
Im coding a music player in python using pyqt and I wanted it to feature mono playback of mp3 files.
I've accomplished that using pygame, as its mixer has a specific parameter channels that I can set to 1 to get mono playback.
However, pygame mp3 support is limited, so I'm searching for a library that will be able to handle mp3 files AND mono playback.
Currently, I'm using pyaudiere for playback and on its site there's an example of processing the song before playing it, so maybe I could do that to turn the song to mono, but I really have no idea how to accomplish that.
I'd like help on how to code this feature using pyaudiere or any other library that can handle mp3 files.
EDIT
I would also accept a solution in C++, as I can always build a python wrapper using Boost::python
IF you want really good Windows support I suspect you might need or find it easier to use a different API for Windows... check these links:
http://people.csail.mit.edu/hubert/pyaudio/ (cross-platform)
http://ffmpeg.org/ffmpeg.html (cross-platform)
http://www.codeproject.com/KB/audio-video/MP3Example.aspx (Windows-specific)
http://msdn.microsoft.com/en-us/library/windows/desktop/dd743572%28v=vs.85%29.aspx (Windows-specific)
EDIT - most probably the solution (so far the comments are pretty positive):
Another option is http://www.un4seen.com/bass.html (beware: commercial) - it does all you asked for, is free for use in non-commercial applications and there is a python wrapper (called pybass)...
Have you considered Python Audio Tools? It has the ability to load an MP3 and play it using the Player class. The Player class initializer accepts an AudioOutput object, which lets you specify the number of playback channels.
The project seems well supported with the last git commit on October 30th of 2011 (just under two weeks prior to your posting). It's also been around for a while, so it doesn't appear to be a fly-by-night library.
Gstreamer's Python bindings.
Here's a very simple music player:
import gobject
import gst
pipeline = gst.parse_launch('filesrc location="stereo.mp3" ! mad ! audioconvert ! audio/x-raw-int,channels=1 ! autoaudiosink')
pipeline.set_state(gst.STATE_PLAYING)
gobject.threads_init()
gobject.MainLoop().run()
I really suggest you look into Gstreamer as it has become a de-facto multimedia solution for most of the open source platforms and supports a wide variety of audio files. Sample apps using it: Rhythmbox, Banshee, Totem, etc...
While this is not even close to a complete answer, to turn a multichanneled audio wav file into a mono one, you simply get the average of all the channels.
In the case of stereo you would have:
mono[i]=(left[i]+right[i])/2
for each sample i.
Hope it helps!