0

I'm playing a MIDI file, and I have a timer which periodically checks the status of the alias. When it is stopped, this executes:

mciSendString(L"seek Music to start", NULL, 0, NULL);
mciSendString(L"play Music", NULL, 0, NULL);

I'm using this as a part of a basic game I'm creating. I've noticed that whenever the song repeats, there's a split second where the application freezes. I thought this was caused by me loading the file each time, but if I already have it loaded and am just seeking within it, it shouldn't slow down, should it? How can I keep it from delaying?

I know MCI probably isn't the best option for playing midi files. However, all my program needs is to load two midi files into memory and play them on a loop. Originally I looked into third-party libraries, but most of these seem like WAY more than I need, and a lot of them are much too prohibitively complicated. However, if there was a really basic, simple one out there which would accomplish what I need, I would love to hear about it. I'm not looking for multilayer 3d sound or anything - just the ability to load to memory, play and repeat.

Brian Gradin
  • 2,165
  • 1
  • 21
  • 42
  • I have this same issue, and the complexity of using a thread really isn't an option for me, and I don't think it would solve the problem anyway. I'm not sure what to do either, I'm using it to loop an mp3 and there's a very obvious/annoying split second delay every time it loops. – MasterHD Dec 06 '13 at 06:51
  • The complexity of using a thread isn't a option? Are you just unsure of how to use threads, or are you working with hardware which actually disallows threads? – Brian Gradin Dec 06 '13 at 22:59
  • It's in Ruby, and the compiler is bare minimum (RPGXP). But like I said, calling MCI commands to play an mp3 hands control over to the OS which appears to use a different CPU to handle the playback operations (on multicore system), so I don't think threading would be of any use. I think the real problem is just that MCI isn't a great player. It can't even predict buffering the beginning of a file before reaching the end. – MasterHD Dec 07 '13 at 10:25

2 Answers2

1

I was talking to a friend, and he recommended that I use a thread. "Well, duh", I thought. "How could I possibly have not thought of that?"

Brian Gradin
  • 2,165
  • 1
  • 21
  • 42
0

I was having the same problem until I switched out "play 000mp3" for "play 000mp3 from 0" for each call. Not sure why that makes a difference, but the difference is not marginal - especially when the call is rapidly repeated. i.e. when linked to a key that's pressed rapidly. Also had mixed results playing around the last three arguments - switching between NULL, and 0. But nothing too reliable as far as I could tell. I'm still undecided on whether the difference is reliable enough for a game - where buttons are often bashed repeatedly - but it's much faster.

  • Also, if you're not limited to MP3 usage for smaller files like sound effects, the following post has just saved me a lot of time: https://stackoverflow.com/questions/22253074/how-to-play-or-open-mp3-or-wav-sound-file-in-c-program – Jonathan Deans Jun 01 '22 at 08:49