Page 1 of 1
Syncing Playback of multiple audio files.
Posted: Fri Apr 01, 2011 6:01 am
by Howlernator
Hiya Folks,
Just sharing a tiny bit of love here....that has replaced oodles of complexity with attempts at, callbacks that don't work in loop mode, custom timers etc...
If you have a bunch of audio samples that you want to trigger from a single event, and would like them to playback in time, it's hard, as you cannot actually issue a simultaneous 'start' command to multiple player or audioclip objects.
So, a simple workaround... for those who come after me....
Code: Select all
on playLoopSounds
start player "Player 1"
start player "Player 2"
set the currentTime of player 2 to the currentTime of player 1
start player "Player 3"
set the currentTime of player 3 to the currentTime of player 1
start player "Player 4"
set the currentTime of player 4 to the currentTime of player 1
start player "Player 5"
set the currentTime of player 5 to the currentTime of player 1
end playLoopSounds
...works pretty nicely here, is not tooo noticable on playback, and SHOULD scale ok on different processors etc...
you can also trigger this command sequence with offset calcs to handle beat displacement in audio samples as well....one for the musicologists!
I'd love to hear about others techniques /attempts at solving this one...
regards,
Anthony.
Re: Syncing Playback of multiple audio files.
Posted: Wed Apr 27, 2011 7:59 pm
by karmacomposer
This is EXACTLY what I am interested in. I am looking to create a small version of a DAW/Multitrack with multiple tracks of audio that can be played together using drag and drop for the actual music. After someone is done, I would like the program to 'render' the resulting, mixed wave file (two track). It would be critical to use a grid snap methodology.
Dreaming for a moment, I would not mind also having a video window so you could sync a video to the music - so that I could compose with it.
Lastly, I would love to create the ability to lay down markers so you could drag and drop other audio elements onto those markers.
Is all this theoretically possible with Live Code?
Mike
Re: Syncing Playback of multiple audio files.
Posted: Wed Apr 27, 2011 9:07 pm
by karmacomposer
Howlernator wrote:Hiya Folks,
Just sharing a tiny bit of love here....that has replaced oodles of complexity with attempts at, callbacks that don't work in loop mode, custom timers etc...
If you have a bunch of audio samples that you want to trigger from a single event, and would like them to playback in time, it's hard, as you cannot actually issue a simultaneous 'start' command to multiple player or audioclip objects.
So, a simple workaround... for those who come after me....
Code: Select all
on playLoopSounds
start player "Player 1"
start player "Player 2"
set the currentTime of player 2 to the currentTime of player 1
start player "Player 3"
set the currentTime of player 3 to the currentTime of player 1
start player "Player 4"
set the currentTime of player 4 to the currentTime of player 1
start player "Player 5"
set the currentTime of player 5 to the currentTime of player 1
end playLoopSounds
...works pretty nicely here, is not tooo noticable on playback, and SHOULD scale ok on different processors etc...
you can also trigger this command sequence with offset calcs to handle beat displacement in audio samples as well....one for the musicologists!
I'd love to hear about others techniques /attempts at solving this one...
regards,
Anthony.
Anthony,
As a total noob to Live Cube (but not to programming), how would I implement the above code in an actual example?
Using one of the tutorials, I created three buttons (PLAY GROOVE 1, PLAY GROOVE 2 and STOP). I would like to do the following:
1) Play sound 1
2) Play sound 2
3) stop them.
Now, I can play sound 1. When I press the button for sound 2, sound 1 stops playing. I need it so that when I press sound 2, BOTH sound 1 and sound 2 play together.
Also, how do I keep them synced REGARDLESS of when I press the button (so they are always in sync). Both sounds are identical in size and tempo (2 bar grooves).
Here is the code for button 1:
on mouseUp
Play audioClip "c:\samples\loops\series1\Drum_Groove.wav" LOOPING
end mouseUp
And for button 2:
on mouseUp
Play audioClip "c:\samples\loops\series1\groove.wav" LOOPING
end mouseUp
It should be noted that the following works perfectly and the two sounds play in sync and loop perfectly:
on mouseUp
Play audioClip "c:\samples\loops\series1\Drum_Groove.wav" LOOPING
Play audioClip "c:\samples\loops\series1\groove.wav" LOOPING
end mouseUp
Thank you for your help.
Mike
Re: Syncing Playback of multiple audio files.
Posted: Wed Apr 27, 2011 9:25 pm
by karmacomposer
I am going to apologize in advance. I am VERY excited about using Live Code now that I "discovered" it. The questions will come fast and furious, and for that, I am sorry.
I thank any and all of you that can help me while I quickly come to terms with this language. I will be reading all the docs and using all the tutorials to get up to speed as quickly as possible. However, like most people, I like to jump right in.
So, next question:
How would I create a live graphic of the waveform in question and allow the user to drag and drop it onto a "track".
I KNOW this is a loaded question. First, I have to create "tracks" and then I have to create the rectangular objects. Then I have to figure out how to draw the current chosen waveform inside the colored rectangle (and also how to auto color the rectangle per track) and then figure out drag and drop as well as SNAPPING each rectangle together, like building blocks.
I am sure this is a massive task, but I want to create my own version of a tiny DAW for playing around with my grooves and what not.
Thanks for the help getting this started.
Mike
Re: Syncing Playback of multiple audio files.
Posted: Thu Apr 28, 2011 7:25 pm
by neo42
I have thought about drop/drop and snapping a little bit.
On IOS I got started using the tutorial online from RunRev.
TouchStart for example.
On desktop I think it'd be Mousedown. Though I think there are some built in drag events.
In any case you usually have 3 events. MouseDown, MouseMove and MouseUp. On mouseup is when the touch/click ends. Also, on desktop, MouseMove would likely cover any time the mouse is moved around the screen so you might need to start tracking with a value when the mousedown starts/occurs.
Anyhow. On mouseup is when I would detect where the object is now from the drag. Based on this, you could try intersecting it with other objects in a grid to see which one has the the most similar X,Y position. That works well with squares.
You could MOD divide the X, Y by some grid width value to determine where the ending X, Y coordinates should be. For example, if your grid width is 50 and the ending x value is 60, then you would snap to 50. If the ending X was 120, you'd snap to 100. If the ending X was 126, you'd snap to 150 (150 is closer). The math would be MOD (newX) < 26 then make it the lower X value. If > 25 then it'd be the higher X value.
Re: Syncing Playback of multiple audio files.
Posted: Mon May 30, 2011 7:04 pm
by admin12
Thank you. I am getting started on this project and right now I am trying to figure out how to draw the waveform provided from a wave file. Any thoughts? Creating the grid and snap is next.
Mike
Re: Syncing Playback of multiple audio files.
Posted: Mon May 30, 2011 8:10 pm
by jacque
There is a full suite of commands and messages to support drag and drop on the desktop. No need to do any calculations on your own. In particular, see the dragStart, dragAction, dragMove, and dragEnd entries in the dictionary. Unfortunately drag and drop is not yet supported on mobile devices. For that you may have to write your own workaround.
Re: Syncing Playback of multiple audio files.
Posted: Mon May 30, 2011 8:41 pm
by admin12
Yeah, I am beginning to see that LiveCode for mobile is going to be tough for my desired apps. Drag and drop plays a big role in my software I am creating.
Mike
Re: Syncing Playback of multiple audio files.
Posted: Tue May 31, 2011 3:59 am
by jacque
Oh, I think you can do it, it just won't be as easy. You might be able to get away with just using the "grab" command if you are dragging objects; then on mouseUp or mouseRelease, check what object the mouse is over. If you just need to drag text from one field to another, that's built in already and you don't need to do anything at all. What do you need to drag/drop exactly?
Re: Syncing Playback of multiple audio files.
Posted: Tue May 31, 2011 5:41 am
by admin12
I just found that cool waveform drawing stack. I plan on either drawing the waveform, taking a picture of it and superimposing it over a glossy rectangle, then take a picture of that and those will be my final blox. They will be color coded depending on what blox they are (drums, bass, synth, etc). The user should be able to choose a folder filled with blox and the software will automatically load them all in, convert them to the picture blox (with file name) and set them up in the holding cell - organizing them by type.
Every wav file is exactly 2 measures/bars, so the snap to grid will be very easy - no guesswork on the length. All the wav files can be mixed and matched to create grooves. The snap to grid should be stupid easy - pretty much magnetic - so that the user cannot make a mistake with the groove. No grooves will overlap on the same track, ever (they are always 2 bars). It may sound rigid, but it guarantees total beginners can make great grooves and have fun with it.
I want the user to be able to drag and drop BLOX into place over many tracks and 'sculpt' their groove. When done, I want to be able to render that groove to a two track wave file.
Further, I would like to eventually add a video window for simple foley and sfx placement.
I would like the blox to be in a holding cell on the left (like in tetris) and the user auditions them, and drag and drops them into place. I want the blox to be moveable in case they want to try something else and the user should be able to delete blox they don't want.
That's the general idea. I already have many grooves created, so I can test it right away. I will eventually have hundreds of blox to play with, mix and match and see what happens.
Mike
Re: Syncing Playback of multiple audio files.
Posted: Tue May 31, 2011 2:20 pm
by neo42
jacque wrote:There is a full suite of commands and messages to support drag and drop on the desktop. No need to do any calculations on your own. In particular, see the dragStart, dragAction, dragMove, and dragEnd entries in the dictionary. Unfortunately drag and drop is not yet supported on mobile devices. For that you may have to write your own workaround.
Implementing drag and drop without those events is still easy.
On TouchStart
TouchMove - Touchmove has the details on where the finger's x, y is. Look at the ios release notes. ON touchmove you set the location of your object to the touchmove x y
TouchEnd - at touchend you loop through an array of every object you want to test for intersection with. Whichever one is closest is where your object will get it's final set location command.
Using those 3 events on the object being dragged you can accomplish a lot.
It might not be as easy as the desktop's events, but it's not horrible.
Re: Syncing Playback of multiple audio files.
Posted: Tue May 31, 2011 4:29 pm
by admin12
Great. I will get this coded this weekend and give it a go.
Thanks for the help. More questions to come I am sure!
Mike
Re: Syncing Playback of multiple audio files.
Posted: Wed Jun 29, 2011 6:02 pm
by jrioux
I'm responding to the initial poster, who wanted to hear other ways of synching multiple audio files than his method (which was to set the start time of subsequent players to former ones).
Why not put all the audio, already synched, into multiple tracks of a single player? Then you can turn tracks on and off at will, and all tracks (separate files, in your original solution), whether audible or not, will always play in synch.
Aesthetically preferable to simply turning tracks on and off, at least for my purposes, is fading individual tracks in and out using the Enhanced QT External. In my setup, separate instrument-sets (percussion, strings, horns, etc.) come in, in response to the user's actions (they "know" they're getting closer to a solution as the music "builds").