So, I've been working on a project that is going to require the playback of Midi. I have already done this with a little bit of code that looks like this:
mciSendString(L"play C:\\aha.mid", NULL, 0, NULL);
And that works perfectly fine for playing a Midi file.
But, what I also need to do is to get the note events from the playback of the midi file itself. I've seen a great deal of libraries that can help with playback or with reading the raw data of the midifile, but not both, and not both at the same time. I've tried Midifile, did some searching around the Juce library, but nothing seems to get the functionality that I need.
Is there something out there that can solve my problem or am I just thinking about this problem the wrong way? Maybe there's some way to get the current notes being played on the Microsoft wavetable (would be much easier if that's possible).
Related
I'm trying to work with an old version of DirectX (8.1) and I'm finding the documentation more than a little confusing. It feels like the IDirectMusicPerformance8 interface is for MIDI playback, as it has various MIDI-related methods on it, but various parts of the documentation suggest that it can be used to play back WAV data as well. For instance, the tutorial says that you call InitAudio on the performance, and it states "Wave files require only a single performance channel, and MIDI files require up to 16".
So is it for MIDI or can it be used for WAV?
If it can be used for WAV, I'm even more stumped, because I'm initializing it, running performance->PlaySegment(segment, 0, 0, NULL), getting a success response, but the audio is silent.
OK, I figured it out. Apparently I had been using IDirectMusicPerformance instead of IDirectMusicPerformance8, which I guess is some kind of old compatibility thing that is missing various new DirectX 8.1 methods. Once I switched to that (along with the associated '8' versions of the loader and segment interfaces), used their new InitAudio and LoadObjectFromFile methods, called segment->Download(performance) before playing, then played with the new PlaySegmentEx method, it worked and played the WAV.
I just need a simple program which allows me to play and stop an audio file. I'm guessing OpenAL is the way to go? All I need is this functionality - start audio file with spacebar and stop audio file with a second press of the spacebar. I notice the OpenAL documentation is quite involved. Can someone point me to something really simple in order to just get the start/stop functionality of a .wav file?
OpenAL may not be the simplest choice. If you use a gui-framework like QT, check for what their ecosystems provide for playing sound (e.g. qsound). Another choice may be Allegro which may feel more straightforward.
For OpenAL, there is a working example to play a wav in the example repositories. Playback can be paused using alSourcePause.
Edit:
For choosing libraries I like to consult Awesome-cpp. The simple_playback.c example of mini_al looks extremely straightforward. Simply use mal_device_stop(&device) to pause the running playback and mal_device_start(&device) to continue. Works perfectly on my machine and seems very portable.
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)
I'm trying to make a piece of software using C++ that plays a .wav audio sample when a certain MIDI key is pressed. The best way I thought about doing this is using an if statement (if there's an easier way I would much appreciate it, but I'm quite the novice to programming so please keep it simple).
Having looked online, I've found out that different MIDI keys correspond to different NOTE ON messages (for example, NOTE ON 60 would correspond to middle C), so basically I'm just looking for how to say "when NOTE ON 60 is received, play X .wav file". I've also found out that the status for NOTE ON is 9n, so would this mean the computer would receive 9x60 (using the 60 = Middle C example)?
After this I would just need to find out how to play an audio sample, which I believe would be the following, using sndfile.h:
SNDFILE *sndFile = sf_open("Sample1.wav").
Any help would be very greatly appreciated.
you can use
PortAudio
it has everything that you can work with midi and your wave files
you can implement a stream function with portAudio and check with portMidi that when note c4 for example is pressed, play that file
look at there documentation
I am using Windows 7 and developing a chat-like application with Visual Studio 2010. I am looking for an EASY way of capturing audio from a microphone (or rather, from the default recording device), collect the buffer from said input, and send it over a socket. I've seen DirectX solutions recommended, but from my research that is quite the opposite of simple. 5000 lines of sample code for a simple capture/save file program? That simply doesn't work for me (and yes, that was an official sample provided with the SDK).
Anyway, I don't need it to be cross-platform, and I would really prefer something that already comes with Windows, though I don't mind installing a library as long as it doesn't take longer than writing the hardware drivers from scratch to figure it out (exaggeration). I've heard of this waveInOpen function, but oddly enough I cannot find any demos on how to use it. If anyone has an idea or a link to some sample code, I would greatly appreciate it. Thanks everyone for your time!
P.S. I can figure out the networking part myself. I just need access to the raw audio data buffer.
If you're doing the sockets yourself try checking out:
http://www.techmind.org/wave/
http://www.bcbjournal.com/articles/vol2/9810/Low-level_wave_audio__part_3.htm
http://www.relisoft.com/freeware/recorder.html
I enjoyed all of them but the last one, but then again, you might find it far more helpful.