Looping Sound in Cocoa

RigelPrime
Unregistered
 
Post: #1
Does anyone have experience playing sounds in Cocoa? Specifically, I'm trying to make the sound loop, but I'm having no luck. Here is my current strategy:

1. Declare and create the sound. Play it. No problem.

NSSound* mySound;
mySound = [NSSound soundNamed:@"SomeSound"];
[mySound play];


2. Check to see if the sound is still playing. If not, play it again (Sam).

if (![mySound isPlaying]){
[mySound play];
}

This actually sort of works except that there is a short pause after the sound is finished and before it starts playing again. My sound is a drum track, so obviously this is not acceptable.

CAN ANYBODY HELP ME!?

Thanks.
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #2
How often do you check if your sound is playing? You could setup a timer to fire at 0.001 to check it or just check in drawRect (or any other method that gets called often).

NSMovieView has a mode where you can set the movie (sound) to loop, but it doesn't seem to work. Huh
Quote this message in a reply
Member
Posts: 304
Joined: 2002.04
Post: #3
well NSSound sends a

sound:didFinishPlaying:

message to its delegate when it finishes playing. So you could use that to replay the sound. Im guessing its still not going to be a flawless loop. But much better than using a timer.

hth,
Codemattic

PS - it does seem a little wierd that it would send a BOOL tho. I mean that BOOL is always going to be YES since the message is sent only when the sound finishes playing - so whats the point?
Quote this message in a reply
RigelPrime
Unregistered
 
Post: #4
Thanks for the response guys. I do check every 30 miliseconds or so, so it is getting checked often. Also, I read a post somewhere else about someone using the delegate method and they didn't have any luck either.

I don't know what to do then. I guess no drum track. Maybe a very SLOW drum track. Smile
Quote this message in a reply
furballphat
Unregistered
 
Post: #5
Have you made sure the drum loop has no 'whitespace' before or after it? That could cause a problem like this.
Quote this message in a reply
RigelPrime
Unregistered
 
Post: #6
Nope. No white space, unless it is hidden somehow. I used Sound Studio to crop the sound, so unless there is space before or after that isn't shown, it isn't there. Good suggestion, though!
Quote this message in a reply
Tyrtael
Unregistered
 
Post: #7
im not very experienced in the cocoa language, (if you can call it that..) but doesn't it use quicktime to play sounds? if thats true, it would take a significant amount of time to access the sound, anyways, my two cents.

Good luck,
Tyrtael
Quote this message in a reply
RigelPrime
Unregistered
 
Post: #8
You are right. It does use Quicktime to play sounds. I found out that it didn't used to, though. Maybe not enough people have complained so far. I might have to send an e-mail to their technical staff to change it. Quicktime lets you loop (command-L), so why not NSSound?
Quote this message in a reply
blb
Unregistered
 
Post: #9
This was one of those things buried in the 10.2 AppKit release notes. The fact you now need the run loop active has caught several people so far.
Quote this message in a reply
RigelPrime
Unregistered
 
Post: #10
Blb,

Thanks for finding that paragraph in the AppKit release notes. They aren't clear in there exactly what would be required to make the sound loop indefinitely. I think the loop they were referring to is something else. Some sort of logical loop perhaps.
Quote this message in a reply
RigelPrime
Unregistered
 
Post: #11
I think I will try two things. First, mix Carbon with my Cocoa (Yummy!). Carbon has a function called SndPlayDoubleBuffer. Second, I might try using a quicktime movie that is sound only. That might work.

Thanks for all of your help!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #12
Code:
/*
*  SndPlayDoubleBuffer()
*  
*  Availability:
*    Mac OS X:         not available
*    CarbonLib:        not available
*    Non-Carbon CFM:   in InterfaceLib 7.1 and later
*/
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Trouble with Time and GLUT looping mechanisms Jones 22 7,603 Aug 14, 2006 02:02 PM
Last Post: ermitgilsukaru