I'm writing a tiny music program and I'm trying to play an mp3. Right now, I have something pretty ugly but it works:
std::string command("cd \"C:\\Program Files (x86)\\Windows Media Player\" && wmplayer /play \"D:\\music\\A Perfect Circle\\eMOTIVe\\a.mp3");
system(command.c_str());
Is there a better or more reliable way to do this? Also, how would one go about adjusting the master system volume?
If there is an MP3 codec installed in Windows, you might be able to use the Win32 API PlaySound() function or the VCL TMediaPlayer component to play the file.
To set the master volumne, use the Win32 API waveOutSetVolume() function.
I've created a C++ audio library named "Crosstalk".
Crosstalk is a real-time C++ audio engine that allows you to create and route audio systems.
Here's an example of how you can play your mp3 file:
XtSystem system;
XtMp3Decoder mp3Decoder;
XtAudioDevice audioDevice;
long md = system.addComponent(&mp3Decoder);
long ad = system.addComponent(&audioDevice);
system.connOutToIn(md,0,ad,0);
system.connOutToIn(md,1,ad,1);
mp3Decoder.loadFile("../05 Tchaikovski-Swan Lake-Scene.mp3");
mp3Decoder.play();
Included with Crosstalk are example Xcode and Visual Studio projects.
You can download Crosstalk and check out the API documentation and licensing details here.
EDIT:
In terms of setting volume: there is a component included with Crosstalk called "XtGain" that you can wire in series between the mp3 decoder outputs and the audio device inputs. This will allow you to set the volume of the audio stream before it reaches the speakers.
EDIT (01-12-2012):
Crosstalk has been replaced by an open-source project called "DSPatch". DSPatch is essentially an upgraded version of the routing engine behind Crosstalk that is no longer limited to only audio processing. DSPatch allows you to create and route almost any type of process chain imaginable, and its free for personal AND proprietary use :)
Related
I'm currently building a project on C++ using Visual Studio on Windows 8. This application captures video from camera and triggers some virtual animations in real-time, with some sounds being played along with the animations.
The user has the option to record the experience in video and sound. I already am able to record video, now I want to create a audio track of the sounds that are being played by the application, to later fuse both video and audio files.
So, which is the best way to record audio output from an application in windows?
Let me stress that I do NOT want to record audio from any input devices (such as a microphone), only from the application itself.
Best regards.
There is no recording of application output. If you generate audio on your own, you make a copy for the recording purposes, mix if you have multiple sources, and then use one of the APIs to produce a file depending on your preferences: directly writing a WAV file, Windows Media audio files (ASF/WMA), DriectShow, Media Foundation, third party libraries.
Real playback audio data is being mixed and sent for further playback. Sometimes you can enable loopback recording to capture fully mixed output (not just of specific application through) as if it is a capture from realtime audio input device.
I am actually working on a server-client multimedia player. This player can be a server to stream a MP3 file (or wma, wav, ogg, flac ...) over the network to another player (client).
I worked first on a basic network communication (client-server), that send and receive bits. But I have a problem : the audio encoding. I need a tool to encode the audio data to be able to send a little part of it through the network and let the client play it before the next part is coming.
I saw a few tools on internet such as BASS library, Live555 ... I used to work with PortAudio for student's projects but I hate it.
So basically, I need a tool to encode audio data (server side), (I can send it over lan), and decode data to play it (client-side).
Do you guys have some ideas about how to do it ? Which tool could be useful for me in that case?
PS : I am trying to use Qt library for the network interface (it is efficient, and it works on windows, linux, mac) ... Is there any audio streaming tool included in the Qt library ?
You can try FFMPEG. It can convert almost anything to anything (so it claims) and it is a widely used open source library.
We use it in our application mainly for decoding video/audio streams.
I've stumbled through some code to enumerate my microphone devices (with some help), and am able to grab the "friendly name" and "clsid" information from each device.
I've done some tinkering with GraphEd.exe to try and figure out how I can take audio from directshow and write it to a file (I'm not currently concerned about the format, wav should be fine), and can't seem to find the right combination.
One of the articles I've read linked to this Windows SDK sample, but when I examined the code, I ended up getting pretty confused at how to use that code, ie. setting the output file, or specifying which audio capture device to use.
I also came across a codeguru article that has a nicely featured audio recorder, but it does not have an interface for selecting the audio device, and I can't seem to find where it statically picks which recording device to use.
I think I'd be most interested in figuring out how to use the Windows SDK sample, but any explanation on either of the two approaches would be fantastic.
Edit: I should mention my knowledge and ability as a win32 COM programmer is very low on the scale, so if this is easy, just explain it to me like I'm five, please.
Recording audio into file with DirectShow needs you to build the right filter graph, as you should have figured out already. The parts include:
The device itself, which you instantiate via moniker (not CLSID!), it is typically PCM format
Multiplexer component that converts streams into container format
File Writer Filter that takes file-compatible stream and writes into a file
The tricky moment is #2 since there is not standard component available. Windows SDK samples however contains the missing part - WavDest Filter Sample. Building it and making it ready for use, you can build a graph that records from device into .WAV file.
Your graph will look like this, and it's built easily programmatically as well:
I noticed that I have a variation of WavDest installed with Google Earth - for the case you have troubles building it yourself and you will be looking for prebuilt binary.
You can instruct ffmpeg to record from a directshow device, and output to a file.
i am currently writing a script mod for Grand Theft Auto IV using Scripthook C++.
I have been playing audio files by using this template: Simple C++ MP3 Player Class
My problem starts by attempting to use files from resource.
I have no idea how to load them.
Every time i tried to load sound from resource using my code, game crashed.
Already spend hours browsing google about how to play DirectShow audio from resource without any result.
Inside resource files:
(resource.h) #define WAV_Sound 106
(resource.rc) WAV_Sound RCDATA "MySound.wav"
Loading files from HDD is working fine
Load(TEXT("MySound.wav"));
But game crashes when i try one of this:
// Load from resource #1
LPCWSTR file = MAKEINTRESOURCE(WAV_Sound);
Load(file);
// Load from resource #2
Load((LPCWSTR) WAV_Sound);
Hope someone can help me out, thanks !
Microsoft recommended using DirectX Audio to provides multilayer interfaces for developing game, namely XAudio2, X3DAudio, XACT, ... etc, they are very powerful to process sound effect in 2d/3d game environment. Here is the link http://msdn.microsoft.com/en-us/library/ee415737%28v=vs.85%29
Please download and install the DirectX software development kit, and find the 'XAudio2BasicSound' example to open wave file from file or in resource or in dll and playback with IXAudio2 interface, it was very simple example but next step you can add sound effect to your game.
As I've already said in another thread, I'm working on a project related to real-time graphical programming for audio (something like Pure Data, Max/MSP, Reaktor).
I did a day of research on Internet, looking for a good (maintained, well documented and highly portable) C++ library for low level interaction with audio and MIDI, but I still can not make up my mind about a library.
I'm considering PortAudio+PortMIDI (PortMedia), but they lack of documentation (especially PortMIDI) and there is no official community, just a mail list (and I think forum communities are very important!), same (or worst) situation with RTAudio and RTMidi libraries.
I also give a try to:
STK, I dodn't like its file organization.
Juce, I think it does too much for me, I need only an easy hardware integration
OpenAL, I didn't understand its architecture, it relies on ASIO/ALSA/CoreAudio...? Can I access to MIDI port?
So... My question is: have you any experience with real-time audio/MIDI? Which library do you recommend me?
Thanks
I've used both PortAudio/PortMidi and Juce with great results on both. I'm in the process of switching a project over from PortMidi to Juce, because for my uses all that other app framework stuff ends up being incredibly useful (and in my experience, it's rock solid.). YMMV.
I've created a C++ audio library named "Crosstalk".
Crosstalk is a real-time C++ audio engine that allows you to create and route audio systems in real-time (Pretty much what your trying to achieve graphically), and it's really easy to use.
Here's an example of how to play an mp3 file:
XtSystem system;
XtMp3Decoder mp3Decoder;
XtAudioDevice audioDevice;
long md = system.addComponent(&mp3Decoder);
long ad = system.addComponent(&audioDevice);
system.connOutToIn(md,0,ad,0);
system.connOutToIn(md,1,ad,1);
mp3Decoder.loadFile("../05 Tchaikovski-Swan Lake-Scene.mp3");
mp3Decoder.play();
You can check out the API documentation and licensing details here:
http://www.adaptaudio.com/Crosstalk
EDIT (01-12-2012):
Crosstalk has been replaced by an open-source project called "DSPatch". DSPatch is essentially an upgraded version of the routing engine behind Crosstalk that is no longer limited to only audio processing. DSPatch allows you to create and route almost any type of process chain imaginable, and free for personal AND proprietary use :)
I would also recommend openFramworks: http://www.openframeworks.cc/ It is meant for all kinds of media, interaction, ... and it has a very easy to use/understand API, which is also pretty well documented. Just follow the link above and check it out.
Good luck, Audiodroid
In this tutorial series there's a post about reacting to MIDI data. It also covers other topics such as synthesis etc.