[comp.sys.next] SoundKit problem

paul@phoenix.Princeton.EDU (Paul Lansky) (06/21/89)

In the following program the third waitUntilStopped never returns.  Am
I missing some important piece of information?  

#import <objc/objc.h>
#import <soundkit/soundkit.h>
main()
{
	int error,a,b;
	id mySound = [Sound new];
	id copySound = [Sound new];

	a = 100000; b = 50000;

	[mySound readSoundfile:"yy.snd"];

	[copySound copySamples:mySound at:a count:b];

	[copySound play];
	printf("returned first %d\n",[copySound waitUntilStopped]);

	[copySound play];
	printf("returned second %d\n",[copySound waitUntilStopped]);

	[copySound play];
	printf("returned third %d\n",[copySound waitUntilStopped]);
	// ??? never returns from this final wait
}

aozer@NeXT.UUCP (Ali Ozer) (06/27/89)

>In the following program the third waitUntilStopped never returns.  Am
>I missing some important piece of information?  

This is a bug in the 0.9 SoundKit. To get around it, you should use the
Application event loop (with the "run" method) and also use the
Sound class delegation mechanism to get the sound to repeatedly play 
itself. In the simplest case, you'd have a subclass of Application that
looks like:

#import "TestApp.h"
#import <soundkit/Sound.h>

@implementation TestApp

- appDidInit:app
{
    [[[Sound newFromSoundfile:"foo.snd"] setDelegate:self] play];
    return self;
}

- didPlay:sound
{
    [sound play];
}

@end

The above code, coupled with an IB-generated main program and Makefile
will work fine. The advantage of this code is that your events (such as hitting
the "Quit" button) will be detected and processed. And of course it will 
play the sound more than 3 times. 

Ali Ozer, NeXT Developer Support
aozer@NeXT.com

William_Charles_Thibault@cup.portal.com (06/28/89)

I want to repeatedly play a sound seamlessly, without the small pause
that occurs with the examples posted (I tried the SND routines and
the setDelegate:self technique).  The SNDPrepareToPlay routine seems
not to have any effect.  Is there a workaround for this?  Would
accessing the Mach sound driver ports directly be faster?
I'd like to avoid writing DSP code if possible.  Will this be fixed in 1.0?
Will 1.0 support arbitrarily long WaveTables? (This will solve my problem.)
The sounds I want to loop are on the order of a few seconds.
Has anybody done this?

	Bill Thibault
	csuh!tebo@lll-winken.llnl.gov

ali@polya.Stanford.EDU (Ali T. Ozer) (06/29/89)

In article <19933@cup.portal.com> William_Charles_Thibault@cup.portal.com 
writes:
>I want to repeatedly play a sound seamlessly, without the small pause
>that occurs with the examples posted (I tried the SND routines and
>the setDelegate:self technique).  The SNDPrepareToPlay routine seems
>not to have any effect.  Is there a workaround for this?  

No. 1.0 will provide seamless sound playing by allowing you to queue
up sounds at the sound library level. You will also be able to record
into different objects without losing any samples. The 0.9 sound library
does not allow queueing.

>Would accessing the Mach sound driver ports directly be faster?

Yes. Unfortunately, this is highly discouraged at this stage, as this low-level
interface is changing for 1.0.

Ali Ozer, NeXT Developer Support
aozer@NeXT.com