Copy QuickTime audio to another QuickTime movie - c++

I'm trying to copy a section of audio from one QuickTime movie to another one but without success; the audio doesn't seem to be copied.
C++ basic code:
// Copy from another QT movie, *src, to this one
soundTrack = NewMovieTrack(myMovie, 0, 0, kFullVolume);
soundMedia = NewTrackMedia(soundTrack, SoundMediaType,
GetMediaTimeScale(src->soundMedia), NULL, 0);
BeginMediaEdits(soundMedia);
InsertTrackSegment(src->soundTrack, soundTrack, 0,
GetMediaDuration(src->soundMedia), 0);
EndMediaEdits(soundMedia);
I don't want to transcode the sound, just copy the encoded sound frames across. I realise this basic code will copy all of the sound frames in the movie.
I am doing some other editing with the video file so I don't want to go through QTKit if I can possibly help it.

The code is good, I can get sound using it. I made some mistake in another part and ended up selecting the wrong source sequence for the sound. Sorry about that.

Related

Play/Pause/Stop MP3 audio file | (Visual) C++

I want to try and make an MP3 player for Windows. I searched for a function to play audio and found PlaySound() and mciSendString(), from my "research" I found that PlaySound() is only for .wav files, but, for now at least, I want .mp3. I tried mciSendString(), if in the play command, at the end of string I have the parameter "wait"(mciSendString("play audio.mp3 wait", NULL, 0, 0)) then the audio plays fine, but, I can't stop it, I will have to wait(what a surprise) for the audio to end, I found that the wait parameter does that(again, what a surprise). I tried then something like that:
while (!_kbhit()){ //as long as I don't press something
mciSendString("play audio.mp3", NULL, 0, 0); //without the wait
}
I thought that this function might have some sort of pointer that points to where exactly we are in the audio, how much of it we have heard, and with each execution of the command with the same audio, the pointer going, little by little, to the end, to the last "element" of the .mp3 file(note: I don't have the slightest idea how mp3 files and reading from them works)
I seached on the Internet for an example of proper use of mciSendString(), but I couldn't find any clear example/answer or something that works for me, for example, many were saying that still, without the wait it would work, but it didn't. So, here I am now.
What I'm asking: a clear example(code if possible) on how to use mciSendString or other function(s) to do the same thing.
Thank you for listening(reading actually) my problem.

Can I write bytes into audio output using Qt?

There are examples on Qt website regarding using audio API, but frankly I don't really understand them at all.
What I was imagining is writing array of values (bytes, integers...) into some audio buffer and have the sound card "play" them (actually DAC them).
Pseudocode:
// Square wave?
const int values[] = {255,255,255,255, 0,0,0,0, 255,255,255,255 ...};
// Create output that will buffer the bytes and put them on digi to analog converter
RawAudioOutput output(BIT_RATE_CONSTANT, ... some other parameters ...);
output.start();
output.writeBytes(values, sizeof(values));
Can I accomplish something like that? How would I go about it? I know I can model square wave in Audacity (doesn't sound nice), so I guess it's possible. How?
In Qt, if you want to write an array of values into an audio buffer, the class for that is QAudioOutput. The format of the array of values can vary, the PCM format should be supported by all platforms.
Qt ships with an example that demonstrates the usage of QAudioOutput, have a look at that. In the example, the Generator::generateData() function creates the array of values that are then later sent to the audio device.
Of course playing audio from an array of values is quite low-level. With QMediaPlayer, Qt also provides a high-level class to play sound files (.wav, .mp3), video files and even streams.

mp3 to sample array NAudio

How can I use NAudio library to get sample float array from mp3 file?
Here is my code:
float[] buffer = new float[2000];
AudioFileReader reader = new AudioFileReader(filePath);
reader.Read(buffer, 0, 2000);
After that buffer is always empty (only zeros inside).
You could also provide me another useful library in C# to realize this.
You're reading the first 2000 samples which is only going to be around 20ms of audio, so it's quite possible that your MP3 starts with a bit of silence. Have you tried reading further into the file?

Reading midi-files

I'm trying to help out a friend creating a program. And we need to read some midi-file data. I've searched for a good 2 hours now and I can't really seem to find any straight forward ways of doing it.
I've downloaded and hopefully installed SDL_mixer correctly. And managed to play a song with this:
//Initialize sound
SDL_Init(SDL_INIT_AUDIO);
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024);
Mix_VolumeMusic(100);
//Load song
string midiFile = LIB_AUDIO + "redlottery.mid";
Mix_Music *song = Mix_LoadMUS(midiFile.c_str());
//Play song
Mix_PlayMusic(song, 1);
So, what I'm wondering is... Is it possible to extract data using this?
I need things like, note timings. I don't really know how they are structured, but I want to access data. How do you suggest I try doing that?
Thanks!
There are open-source libraries for reading MIDI files. Here are a few:
midifile.sapp.org
naudio.codeplex.com
www.juce.com

MoSync - Edit video

After making a small video recorder application and being able to play that video again. I would like to make the possibility to pick X seconds from the video and put that into a new .MP4 file (or overwrite the old one, that would be even better).
I am using the MoSync C++ Native UI and VideoViewer. I know I can get the position and that part is all fine, and according to the MoSync documentation.
char buf[BUFFER_SIZE];
maWidgetGetProperty(videoViewHandle,
MAW_VIDEO_VIEW_CURRENT_POSITION,
buf,
BUFFER_SIZE);
int seconds = 5;
//So here I need to make a new file ranging from buf to buf + seconds
However, I have absolutely no clue as to where to look for this. Should I use mp4 header files and create my own mp4 (how is this even done? and is this cross-compatible?).
Will appreciate any advice/help you can offer!