23 May '13 - 12:56 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: Looping, with a resampling stream  (Read 1109 times)
JJS
Posts: 102


« on: 8 Jun '08 - 23:34 »
Reply with quoteQuote

In my application, I want to precisely loop either the entire audio file, or some section of the file. I use a WaveForm display to allow the user to set the position, and set the desired loop start/end points.

My question is, do i use the decode channel or the resampling channel with the "set position" function, the loop and end syncs, and the WaveForm?

Thanks,
Logged
radio42
Posts: 4012


« Reply #1 on: 9 Jun '08 - 08:39 »
Reply with quoteQuote

The WaveForm is for visualization only - so it can not loop any channel itself.
I'm not sure what you mean by 'decoding' and 'resampling' channel.

But once you rendered a WaveForm and you are then using another stream channel to perform the playback you are then using that channel and it's positions to call the AddMarker/GetMarker etc. functions.
But make sure to call "SyncPlayback" in advance using this playback channel.

You might also take a look to the C# sample called "Simple" for an example.
Logged
JJS
Posts: 102


« Reply #2 on: 9 Jun '08 - 15:35 »
Reply with quoteQuote

The "Simple" example doesn't address looping and dsps with a "resampling" stream, that is a stream created with BASS_FX_TempoCreate.

Looping, setting DSPs, getting and setting the current position etc is simple when using only one stream, but gets a little complicated when you add the resampling stream. I'm not exactly sure which stream to use when I apply DSPs, get and set positions, and loop so that what you hear stays in sync with what you see (the waveform display), and the looping is accurate and precise.

    stream1 = Bass.BASS_StreamCreateFile(
             filename, 0,  0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN);

    stream2 = BassFx.BASS_FX_TempoCreate(
             stream1, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_PRESCAN);

Assume loopStart and loopEnd have been set to some position:

    hLoopSync = Bass.BASS_ChannelSetSync(
             stream?Huh, BASSSync.BASS_SYNC_POS | BASSSync.BASS_SYNC_MIXTIME, LoopEnd, loopSyncProc, IntPtr.Zero);

In the loop sync proc:

    Bass.BASS_ChannelSetPosition(stream???, loopStart, BASSMode.BASS_POS_BYTES);

Using the WaveForm:

    waveform.SyncPlayback(stream???)

    long pos = Bass.BASS_ChannelGetPosition(stream???);
    long len = Bass.BASS_ChannelGetLength(stream???);

    DrawWavePosition(pos, len);
 

Thanks


Logged
Ian @ un4seen
Administrator
Posts: 15269


« Reply #3 on: 9 Jun '08 - 15:54 »
Reply with quoteQuote

    stream1 = Bass.BASS_StreamCreateFile(
             filename, 0,  0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN);

    stream2 = BassFx.BASS_FX_TempoCreate(
             stream1, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_PRESCAN);

Assume loopStart and loopEnd have been set to some position:

    hLoopSync = Bass.BASS_ChannelSetSync(
             stream?Huh, BASSSync.BASS_SYNC_POS | BASSSync.BASS_SYNC_MIXTIME, LoopEnd, loopSyncProc, IntPtr.Zero);

In the loop sync proc:

    Bass.BASS_ChannelSetPosition(stream???, loopStart, BASSMode.BASS_POS_BYTES);

You should use the source handle ("stream1") in the BASS_ChannelSetPosition call, so that the tempo processing doesn't get reset. I think either handle should be fine in the BASS_ChannelSetSync call, but using the source handle will be slightly less work (internally).
Logged
radio42
Posts: 4012


« Reply #4 on: 9 Jun '08 - 16:27 »
Reply with quoteQuote

For the WaveForm (SyncPlayback) you should use the tempo handle (stream2).
I am personally always use 'stream2' as in your example all the way where you marked 'stream???'.

But Ian is of course right, that you might use 'stream1' in the BASS_ChannelSetPosition call. The difference is, that the tempo stream has an intermediate buffer...so if you set the position on the tempo stream any current processing of buffer data is cancelled and the new position is directly set, which results in retrieving new data from your source (stream1). This means, that in terms of playback position stream2 is the more correct on...as the stream1 position might be a little ahead of what is actually being already processed by the tempo buffer.

But in general:
Any tempo stream will 'only' result in faster/slower playback - so when you call the DrawWaveForm function in constant intervals the position will just faster/slower advance.
DSPs and any other effects shouldn't effect any WaveForm positioning at all.

So I don't really see any more complicated stuff with 'resampling' streams or DSPs.
As a general rule you can say: Use the stream which is being "played out" with the WaveForm methods.
In your case this is stream2.
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines