#import "ITimedSound.h"
#import <libc.h>

@implementation ITimedSound

- (double)time
{
    return(time);
}

- setTime:(double)theTime
{
    time = theTime;
}

- writeStream:(NXStream *)stream
{
    char tempFile[64];
    NXStream *tempStream;
    const char *buffer;
    int len;
    int maxLen;

    sprintf(tempFile, "/tmp/VDR%d.snd", getpid());
    [self writeSoundfile:tempFile];
    tempStream = NXMapFile(tempFile, NX_READONLY);
    NXGetMemoryBuffer(tempStream, &buffer, &len, &maxLen);
    NXWrite(stream, buffer, len);
    NXCloseMemory(tempStream, NX_FREEBUFFER);
    unlink(tempFile);
    return(self);
}

- readStream:(NXStream *)stream
{
    char tempFile[64];

    sprintf(tempFile, "/tmp/VDR%d.snd", getpid());
    NXSaveToFile(stream, tempFile);
    [self readSoundfile:tempFile];
    unlink(tempFile);
    return(self);
}

@end
