20 May '13 - 16:50 *
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: [C#] Incorrect position from BASS_ChannelGetPosition  (Read 489 times)
aevv
Posts: 4


« on: 29 Dec '11 - 19:39 »
Reply with quoteQuote

hi, i've been working on a rhythm game for awhile and part of the song creator allows the user to skip forwards and backwards through songs. I've ran into an mp3 that when skipped forwards or backwards, the position from bass_channelgetposition does not match the actual sound of the music. included below is a test program i used to replicate this (as my original program is too large for here, but uses the same bass code) and a link to the mp3 in question. the tick console write should occur on every beat of the song but after changing position it gives an incorrect value and goes off sync. when tested with other mp3s it works fine.
    class Program
    {
        public static double position
        {
            get
            {
                return Bass.BASS_ChannelBytes2Seconds(handle, Bass.BASS_ChannelGetPosition(handle, BASSMode.BASS_POS_BYTES)) * 1000;
            }
            set
            {
                Bass.BASS_ChannelSetPosition(handle, Bass.BASS_ChannelSeconds2Bytes(handle, value / 1000d));
            }
        }
        static string mp3 = "going brown again.mp3";
        static double tick = 631.578947368421;
        static int handle = 0;
        static void Main(string[] args)
        {
            bool exit = true;
            Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
            handle = Bass.BASS_StreamCreateFile(mp3, 0L, 0, BASSFlag.BASS_DEFAULT);
            Bass.BASS_ChannelPlay(handle, true);
            new Thread(new ThreadStart(report)).Start();
            while (exit)
            {
                ConsoleKeyInfo k = Console.ReadKey();
                switch (k.Key)
                {
                    case ConsoleKey.UpArrow:
                        position += tick;
                        break;
                    case ConsoleKey.DownArrow:
                        position -= tick;
                        break;     
                    case ConsoleKey.X:
                        Environment.Exit(0);
                        break;
                }
            }
        }
        public static void report()
        {
            bool toOut = true;
            while (true)
            {
                if (position % tick < 20 && toOut == true)
                {
                    Console.WriteLine("tick " + position);
                    toOut = false;
                }
                if (position % tick > 20)
                {
                    toOut = true;
                }
                Thread.Sleep(1);
            }
        }
    }
http://www.mediafire.com/?oetvn5ksi4brjvi mp3 in question can be found here
any help on ways to fix this or whats wrong with the mp3 would be appreciated, thanks
Logged
gnag
Posts: 160


« Reply #1 on: 29 Dec '11 - 20:43 »
Reply with quoteQuote

Did you tried to use the Prescan Flag when creating your stream from the MP3 ?

Quote
BASS_STREAM_PRESCAN
Enable pin-point accurate seeking (to the exact byte) on the MP3/MP2/MP1 stream.
This also increases the time taken to create the stream, due to the entire file being pre-scanned for the seek points. Note: BASS_STREAM_PRESCAN is ONLY needed for files with a VBR, files with a CBR are always accurate.

Example:
int fileplay_handle = Bass.BASS_StreamCreateFile("test.mp3", 0, 0,  BASSFlag.BASS_STREAM_PRESCAN );
Logged
aevv
Posts: 4


« Reply #2 on: 29 Dec '11 - 20:52 »
Reply with quoteQuote

thanks, that is working Cheesy
Logged
gnag
Posts: 160


« Reply #3 on: 29 Dec '11 - 22:27 »
Reply with quoteQuote

Its always a good idea to take a look into the manuals before asking...

How do you the beat marking,does the user have to mark the beats first or are you doing it more automatically like bpm/beat detection?
Logged
aevv
Posts: 4


« Reply #4 on: 30 Dec '11 - 00:14 »
Reply with quoteQuote

using the milisecond duration of a beat (like 333.3333 at 180 beats per minute) and a milisecond offset from the start of the mp3. the example code i gave would work as the start of the song on the mp3 is around -4ms, so no offset is required for the tick to be on every beat of the song. the user can then place sounds/notes on the musical snaps (such as 1/4) to match the song.
follow up question if you dont mind, i posted this some time ago but the only reply i got was that someone would have a look into it. when using a tempo stream, and lowering the tempo, the value from BASS_ChannelGetPosition would be later than the song is actually playing
currentOffset = music.PositionAsMilli + (-7 * (music.Speed / 10));
im using the above line to offset my games position of notes/sounds from the music by 7ms per 10% of speed, which makes the music be much more in sync with the sounds im laying on top of it. was just wondering if theres a better/easier/proper way to sync things? edit forgot to mention this runs in a loop and gets the music position every iteration

and sorry for not reading the manuals fully Sad
« Last Edit: 30 Dec '11 - 00:32 by aevv » Logged
gnag
Posts: 160


« Reply #5 on: 30 Dec '11 - 10:16 »
Reply with quoteQuote

sry, i havent used tempo streams so cant help with this, i am trying hard to implement automatic bpm detection for weeks because the one in bassfx is not reliable enough, didnt you try that too or can give me any tips?
Logged
aevv
Posts: 4


« Reply #6 on: 30 Dec '11 - 12:54 »
Reply with quoteQuote

sorry i never tried it as for a rhythm game even slightly incorrect is too incorrect when it comes to accuracy of the beat
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines