mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 18:11:06 +00:00
NSSound reimplementation
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@28511 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
b6789caaeb
commit
54e2773b7f
16 changed files with 1181 additions and 1993 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
2009-08-22 Stefan Bidigaray <stefanbidi@gmail.com>
|
||||
|
||||
* configure.ac: Updated
|
||||
* Headers/Additions/GNUstepGUI/GSSoundSink.h
|
||||
* Headers/Additions/GNUstepGUI/GSSoundSource.h: Added
|
||||
* Headers/AppKit/NSSound.h: Added new methods
|
||||
* Sound/SndfileSource.m
|
||||
* Sound/AudioOutputSink.m: Added
|
||||
* Source/NSSound.m: Implementation using new bundle based playback.
|
||||
* Tools/gsnd: Removed
|
||||
|
||||
2009-08-22 19:49-EDT Gregory John Casamento <greg.casamento@gmail.com>
|
||||
|
||||
* Headers/Additions/GNUstepGUI/GSTheme.h: Add methods for drawing
|
||||
|
|
83
Headers/Additions/GNUstepGUI/GSSoundSink.h
Normal file
83
Headers/Additions/GNUstepGUI/GSSoundSink.h
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
GSSoundSink.h
|
||||
|
||||
Sink audio data.
|
||||
|
||||
Copyright (C) 2009 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Stefan Bidigaray <stefanbidi@gmail.com>
|
||||
Date: Jun 2009
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, see <http://www.gnu.org/licenses/> or write to the
|
||||
Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef _GNUstep_H_GSSoundSink
|
||||
#define _GNUstep_H_GSSoundSink
|
||||
|
||||
@protocol GSSoundSink <NSObject>
|
||||
|
||||
/** Returns YES if class has the ability of playing audio data
|
||||
* through a playback device playbackDevice, NO otherwise.
|
||||
*/
|
||||
+ (BOOL)canInitWithPlaybackDevice: (NSString *)playbackDevice;
|
||||
|
||||
/** <init/>
|
||||
* Initializes the receiver for output using the defined parameters.
|
||||
* <p><b>WARNING:</b> This method does not open the device, see -open.</p>
|
||||
*/
|
||||
- (id)initWithEncoding: (int)encoding
|
||||
channels: (NSUInteger)channelCount
|
||||
sampleRate: (NSUInteger)sampleRate
|
||||
byteOrder: (NSByteOrder)byteOrder;
|
||||
/** Opens the device for output, called by [NSSound-play].
|
||||
*/
|
||||
- (BOOL)open;
|
||||
/** Closes the device, called by [NSSound-stop].
|
||||
*/
|
||||
- (void)close;
|
||||
/** Plays the data in bytes to the device. Data <i>must</i> be in
|
||||
* the same format as specified in
|
||||
* -initWithEncoding:channels:sampleRate:byteOrder:.
|
||||
*/
|
||||
- (BOOL)playBytes: (void *)bytes length: (NSUInteger)length;
|
||||
|
||||
/** Called by [NSSound-setVolume:], and corresponds to it. Parameter volume
|
||||
* is between the values 0.0 and 1.0.
|
||||
*/
|
||||
- (void)setVolume: (float)volume;
|
||||
/** Called by [NSSound-volume].
|
||||
*/
|
||||
- (float)volume;
|
||||
/** Called by [NSSound-setPlaybackDeviceIdentifier:].
|
||||
*/
|
||||
- (void)setPlaybackDeviceIdentifier: (NSString *)playbackDeviceIdentifier;
|
||||
/** Called by [NSSound-playbackDeviceIdentifier].
|
||||
*/
|
||||
- (NSString *)playbackDeviceIdentifier;
|
||||
/** Called by [NSSound-setChannelMapping:].
|
||||
*/
|
||||
- (void)setChannelMapping: (NSArray *)channelMapping;
|
||||
/** Called by [NSSound-channelMapping].
|
||||
*/
|
||||
- (NSArray *)channelMapping;
|
||||
|
||||
@end
|
||||
|
||||
#endif // _GNUstep_H_GSSoundSink
|
||||
|
96
Headers/Additions/GNUstepGUI/GSSoundSource.h
Normal file
96
Headers/Additions/GNUstepGUI/GSSoundSource.h
Normal file
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
GSSoundSource.h
|
||||
|
||||
Load and read sound data.
|
||||
|
||||
Copyright (C) 2009 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Stefan Bidigaray <stefanbidi@gmail.com>
|
||||
Date: Jun 2009
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, see <http://www.gnu.org/licenses/> or write to the
|
||||
Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef _GNUstep_H_GSSoundSource
|
||||
#define _GNUstep_H_GSSoundSource
|
||||
|
||||
@class NSArray;
|
||||
|
||||
enum
|
||||
{
|
||||
GSSoundFormatUnknown = 0x0000,
|
||||
GSSoundFormatPCMS8 = 0x0001,
|
||||
GSSoundFormatPCM16 = 0x0002,
|
||||
GSSoundFormatPCM24 = 0x0003,
|
||||
GSSoundFormatPCM32 = 0x0004,
|
||||
GSSoundFormatPCMU8 = 0x0005,
|
||||
GSSoundFormatFloat32 = 0x0006,
|
||||
GSSoundFormatFloat64 = 0x0007,
|
||||
|
||||
GSSoundFormatULaw = 0x0010,
|
||||
GSSoundFormatALaw = 0x0011
|
||||
};
|
||||
|
||||
@protocol GSSoundSource <NSObject>
|
||||
|
||||
/** Returns an array of the file types supported by the class.
|
||||
*/
|
||||
+ (NSArray *)soundUnfilteredFileTypes;
|
||||
/** Returns an array of UTIs identifying the file types the class understands.
|
||||
*/
|
||||
+ (NSArray *)soundUnfilteredTypes;
|
||||
/** Returns YES if the class can understand data and NO otherwise.
|
||||
*/
|
||||
+ (BOOL)canInitWithData: (NSData *)data;
|
||||
|
||||
/** <init />
|
||||
* Initilizes the reciever for output.
|
||||
*/
|
||||
- (id)initWithData: (NSData *)data;
|
||||
/** Reads data provided in -initWithData:. Parameter bytes must be big enough
|
||||
* to hold length bytes.
|
||||
*/
|
||||
- (NSUInteger)readBytes: (void *)bytes length: (NSUInteger)length;
|
||||
|
||||
/** Returns the duration, in seconds. Equivalent to [NSSound-duration].
|
||||
*/
|
||||
- (NSTimeInterval)duration;
|
||||
/** Called by [NSSound-setCurrentTime:].
|
||||
*/
|
||||
- (void)setCurrentTime: (NSTimeInterval)currentTime;
|
||||
/** Called by [NSSound-currentTime].
|
||||
*/
|
||||
- (NSTimeInterval)currentTime;
|
||||
|
||||
/** Returns encoding of the audio data.
|
||||
*/
|
||||
- (int)encoding;
|
||||
/** Returns the number of channels.
|
||||
*/
|
||||
- (NSUInteger)channelCount;
|
||||
/** Returns the receiver's sample rate (ie 44100, 8000, etc).
|
||||
*/
|
||||
- (NSUInteger)sampleRate;
|
||||
/** Returns the byte order of the audio data.
|
||||
*/
|
||||
- (NSByteOrder)byteOrder;
|
||||
|
||||
@end
|
||||
|
||||
#endif // _GNUstep_H_GSSoundSource
|
|
@ -6,9 +6,6 @@
|
|||
/* Define to 1 if you have the <aspell.h> header file. */
|
||||
#undef HAVE_ASPELL_H
|
||||
|
||||
/* Define to 1 if you have the <audiofile.h> header file. */
|
||||
#undef HAVE_AUDIOFILE_H
|
||||
|
||||
/* Define to 1 if you have the <cups/cups.h> header file. */
|
||||
#undef HAVE_CUPS_CUPS_H
|
||||
|
||||
|
@ -24,9 +21,6 @@
|
|||
/* Define to 1 if you have the `aspell' library (-laspell). */
|
||||
#undef HAVE_LIBASPELL
|
||||
|
||||
/* Define to 1 if you have the `audiofile' library (-laudiofile). */
|
||||
#undef HAVE_LIBAUDIOFILE
|
||||
|
||||
/* Define to 1 if you have the `gif' library (-lgif). */
|
||||
#undef HAVE_LIBGIF
|
||||
|
||||
|
@ -60,9 +54,6 @@
|
|||
/* Define to 1 if you have the <mntent.h> header file. */
|
||||
#undef HAVE_MNTENT_H
|
||||
|
||||
/* Define to 1 if you have the <portaudio.h> header file. */
|
||||
#undef HAVE_PORTAUDIO_H
|
||||
|
||||
/* Define to 1 if you have the `rint' function. */
|
||||
#undef HAVE_RINT
|
||||
|
||||
|
|
|
@ -3,10 +3,11 @@
|
|||
|
||||
Load, manipulate and play sounds
|
||||
|
||||
Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
Copyright (C) 2002, 2009 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Enrico Sersale <enrico@imago.ro>
|
||||
Date: Jul 2002
|
||||
Written by: Enrico Sersale <enrico@imago.ro>,
|
||||
Stefan Bidigaray <stefanbidi@gmail.com>
|
||||
Date: Jul 2002, Jun 2009
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
|
@ -32,6 +33,10 @@
|
|||
|
||||
#include <Foundation/NSObject.h>
|
||||
#include <Foundation/NSBundle.h>
|
||||
#include <Foundation/NSByteOrder.h>
|
||||
|
||||
#include "GNUstepGUI/GSSoundSource.h"
|
||||
#include "GNUstepGUI/GSSoundSink.h"
|
||||
|
||||
@class NSArray;
|
||||
@class NSData;
|
||||
|
@ -39,39 +44,96 @@
|
|||
@class NSPasteboard;
|
||||
@class NSString;
|
||||
@class NSURL;
|
||||
@class NSThread;
|
||||
@class NSConditionLock;
|
||||
@class NSLock;
|
||||
|
||||
/** Function used to retrieve all available playback devices.
|
||||
* <p>This function is the only way to retrieve possible playback
|
||||
* device identifiers understood by
|
||||
* [NSSound -setPlaybackDeviceIdentifier:].</p>
|
||||
*/
|
||||
NSArray *PlaybackDeviceIdentifiers (void);
|
||||
|
||||
@interface NSSound : NSObject <NSCoding, NSCopying>
|
||||
{
|
||||
NSString *_name;
|
||||
NSString *_uniqueIdentifier;
|
||||
BOOL _onlyReference;
|
||||
id _delegate;
|
||||
|
||||
NSData *_data;
|
||||
float _samplingRate;
|
||||
float _frameSize;
|
||||
long _dataLocation;
|
||||
long _dataSize;
|
||||
long _frameCount;
|
||||
int _channelCount;
|
||||
int _dataFormat;
|
||||
NSData *_data;
|
||||
NSString *_playbackDeviceIdentifier; // Currently unused
|
||||
NSArray *_channelMapping; // Currently unused
|
||||
BOOL _onlyReference;
|
||||
id _delegate;
|
||||
|
||||
id<GSSoundSource> _source;
|
||||
id<GSSoundSink> _sink;
|
||||
NSConditionLock *_readLock;
|
||||
NSLock * _playbackLock;
|
||||
BOOL _shouldStop;
|
||||
BOOL _shouldLoop;
|
||||
}
|
||||
|
||||
//
|
||||
// Creating an NSSound
|
||||
//
|
||||
/** <init/>
|
||||
* Initalizes the receiver object with the contents of file located at path.
|
||||
* If byRef is set to YES only the name of the NSSound is encoded with
|
||||
* -encodeWithCoder:; if set to NO the data is encoded.
|
||||
* <p>See Also:</p>
|
||||
* <list>
|
||||
* <item>-initWithContentsOfURL:byReference:</item>
|
||||
* <item>-initWithData:</item>
|
||||
* </list>
|
||||
*/
|
||||
- (id)initWithContentsOfFile:(NSString *)path byReference:(BOOL)byRef;
|
||||
/** <init/>
|
||||
* Initializes the receiver object with the contents of the data located in
|
||||
* url. If byRef is set to YES only the name of the NSSound is encoded with
|
||||
* -encodeWithCoder:; if set to NO the data is encoded.
|
||||
* <p>See Also:</p>
|
||||
* <list>
|
||||
* <item>-initWithContentsOfFile:byReference:</item>
|
||||
* <item>-initWithData:</item>
|
||||
* </list>
|
||||
*/
|
||||
- (id)initWithContentsOfURL:(NSURL *)url byReference:(BOOL)byRef;
|
||||
/** <init/>
|
||||
* Initializes the receiver object with the contents of data with a
|
||||
* valid magic number.
|
||||
* <p>See Also:</p>
|
||||
* <list>
|
||||
* <item>-initWithContentsOfFile:byReference:</item>
|
||||
* <item>-initWithContentsOfURL:byReference:</item>
|
||||
* </list>
|
||||
*/
|
||||
- (id)initWithData:(NSData *)data;
|
||||
- (id)initWithPasteboard:(NSPasteboard *)pasteboard;
|
||||
|
||||
//
|
||||
// Playing
|
||||
//
|
||||
/** Pauses audio playback.
|
||||
* <p>Returns NO if receiver could not be paused or is already paused,
|
||||
* and YES if receiver was successfully paused.</p>
|
||||
*/
|
||||
- (BOOL)pause;
|
||||
- (BOOL)play;
|
||||
/** Start audio playback. Playback is done asynchronously.
|
||||
* <p>Returns NO if receiver is already playing or if an error occurred, and
|
||||
* YES if receiver was started successfully.</p>
|
||||
*/
|
||||
- (BOOL)play;
|
||||
/** Resume audio playback after a -pause.
|
||||
* <p>Returns NO if receiver is already playing or if an error occurred, and
|
||||
* YES if receiver was successfully restarted/resumed.</p>
|
||||
*/
|
||||
- (BOOL)resume;
|
||||
/** Stop audio playback.
|
||||
* <p>Return YES if receiver was successfully stopped.</p>
|
||||
* <p>This method will close the playback device.</p>
|
||||
*/
|
||||
- (BOOL)stop;
|
||||
/* Returns YES if receiver is playing and NO otherwise.
|
||||
*/
|
||||
- (BOOL)isPlaying;
|
||||
|
||||
//
|
||||
|
@ -84,17 +146,69 @@
|
|||
//
|
||||
// Working with delegates
|
||||
//
|
||||
/** Returns the receiver's delegate
|
||||
*/
|
||||
- (id)delegate;
|
||||
/** Sets the receiver's delegate
|
||||
*/
|
||||
- (void)setDelegate:(id)aDelegate;
|
||||
|
||||
//
|
||||
// Naming Sounds
|
||||
// Sound Information
|
||||
//
|
||||
+ (id)soundNamed:(NSString *)name;
|
||||
/** Provides an array of file types that NSSound can understand. The returning
|
||||
* array may be directly passed to [NSOpenPanel -runModalForTypes:].
|
||||
* <p>Built with libsndfile:</p>
|
||||
* wav, aiff, aifc, aif, au, snd, mat, mat4, mat5, paf, sf, voc, w64,
|
||||
* xi, caf, sd2, flac, ogg, oga
|
||||
* <p>Built without libsndfile:</p>
|
||||
* wav, aiff, aifc, aif, au, snd
|
||||
*/
|
||||
+ (NSArray *)soundUnfilteredFileTypes;
|
||||
/** Returns the name of the receiver. Use -setName: to set the name.
|
||||
*/
|
||||
- (NSString *)name;
|
||||
/** Sets the receiver's name. Method -name will return aName.
|
||||
*/
|
||||
- (BOOL)setName:(NSString *)aName;
|
||||
|
||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST)
|
||||
+ (NSArray *)soundUnfilteredTypes;
|
||||
/** Returns the length, in seconds, of the receiver.
|
||||
*/
|
||||
- (NSTimeInterval)duration;
|
||||
/** Returns the volume of the receiver.
|
||||
* Volume will be between 0.0 and 1.0.
|
||||
*/
|
||||
- (float)volume;
|
||||
/** Sets the volume of the receiver.
|
||||
* Volume must be between 0.0 and 1.0.
|
||||
*/
|
||||
- (void)setVolume: (float)volume;
|
||||
/** Returns the current position of the audio playback.
|
||||
*/
|
||||
- (NSTimeInterval)currentTime;
|
||||
/** Sets the current time of the audio playback.
|
||||
*/
|
||||
- (void)setCurrentTime: (NSTimeInterval)currentTime;
|
||||
/** Returns the current loop property of the receiver.
|
||||
* YES indicates this NSSound will restart once it reaches the end,
|
||||
* otherwise NO.
|
||||
*/
|
||||
- (BOOL)loops;
|
||||
/** Sets the loop property of the receiver.
|
||||
* YES indicates this NSSound will restart once it reaches the end,
|
||||
* otherwise NO.
|
||||
*/
|
||||
- (void)setLoops: (BOOL)loops;
|
||||
|
||||
- (NSString *)playbackDeviceIdentifier;
|
||||
- (void)setPlaybackDeviceIdentifier: (NSString *)playbackDeviceIdentifier;
|
||||
- (NSArray *)channelMapping;
|
||||
- (void)setChannelMapping: (NSArray *)channelMapping;
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
//
|
||||
|
@ -102,6 +216,9 @@
|
|||
//
|
||||
@interface NSObject (NSSoundDelegate)
|
||||
|
||||
/** Method called when sound has finished playing. Currently this method
|
||||
* is not called.
|
||||
*/
|
||||
- (void)sound:(NSSound *)sound didFinishPlaying:(BOOL)aBool;
|
||||
|
||||
@end
|
||||
|
|
170
Sounds/AudioOutputSink.m
Normal file
170
Sounds/AudioOutputSink.m
Normal file
|
@ -0,0 +1,170 @@
|
|||
/*
|
||||
AudioOutputSink.m
|
||||
|
||||
Sink audio data to libao.
|
||||
|
||||
Copyright (C) 2009 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Stefan Bidigaray <stefanbidi@gmail.com>
|
||||
Date: Jun 2009
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, see <http://www.gnu.org/licenses/> or write to the
|
||||
Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <GNUstepGUI/GSSoundSource.h>
|
||||
#include <GNUstepGUI/GSSoundSink.h>
|
||||
#include <ao/ao.h>
|
||||
|
||||
@interface AudioOutputSink : NSObject <GSSoundSink>
|
||||
{
|
||||
ao_device *_dev;
|
||||
int _driver;
|
||||
ao_sample_format _format;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation AudioOutputSink
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
/* FIXME: According to the docs, this needs a corresponding ao_shutdown(). */
|
||||
ao_initialize ();
|
||||
}
|
||||
|
||||
+ (BOOL)canInitWithPlaybackDevice: (NSString *)playbackDevice
|
||||
{
|
||||
// This is currently the only sink in NSSound, just say
|
||||
// YES to everything.
|
||||
/* FIXME: What is OS X's identifier for the main sound? */
|
||||
return (playbackDevice == nil ? YES : NO);
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (id)initWithEncoding: (int)encoding
|
||||
channels: (NSUInteger)channelCount
|
||||
sampleRate: (NSUInteger)sampleRate
|
||||
byteOrder: (NSByteOrder)byteOrder
|
||||
{
|
||||
self = [super init];
|
||||
if (self == nil)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
_format.channels = (int)channelCount;
|
||||
_format.rate = (int)sampleRate;
|
||||
|
||||
switch (encoding)
|
||||
{
|
||||
case GSSoundFormatPCMS8:
|
||||
_format.bits = 8;
|
||||
break;
|
||||
|
||||
case GSSoundFormatPCM16:
|
||||
_format.bits = 16;
|
||||
break;
|
||||
|
||||
case GSSoundFormatPCM24:
|
||||
_format.bits = 24;
|
||||
break;
|
||||
|
||||
case GSSoundFormatPCM32:
|
||||
_format.bits = 32;
|
||||
break;
|
||||
|
||||
case GSSoundFormatFloat32: // Float and double not supported by libao.
|
||||
case GSSoundFormatFloat64:
|
||||
default:
|
||||
DESTROY(self);
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (byteOrder == NS_LittleEndian)
|
||||
{
|
||||
_format.byte_format = AO_FMT_LITTLE;
|
||||
}
|
||||
else if (byteOrder == NS_BigEndian)
|
||||
{
|
||||
_format.byte_format = AO_FMT_BIG;
|
||||
}
|
||||
else
|
||||
{
|
||||
_format.byte_format = AO_FMT_NATIVE;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)open
|
||||
{
|
||||
_driver = ao_default_driver_id();
|
||||
|
||||
_dev = ao_open_live(_driver, &_format, NULL);
|
||||
return ((_dev == NULL) ? NO : YES);
|
||||
}
|
||||
|
||||
- (void)close
|
||||
{
|
||||
ao_close(_dev);
|
||||
}
|
||||
|
||||
- (BOOL)playBytes: (void *)bytes length: (NSUInteger)length
|
||||
{
|
||||
int ret = ao_play(_dev, bytes, (uint_32)length);
|
||||
return (ret == 0 ? NO : YES);
|
||||
}
|
||||
|
||||
/* Functionality not supported by libao */
|
||||
- (void)setVolume: (float)volume
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
- (float)volume
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
- (void)setPlaybackDeviceIdentifier: (NSString *)playbackDeviceIdentifier
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
- (NSString *)playbackDeviceIdentifier
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)setChannelMapping: (NSArray *)channelMapping
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
- (NSArray *)channelMapping
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -2,8 +2,9 @@
|
|||
# Sounds makefile for GNUstep GUI Library
|
||||
# Copyright (C) 2009 Free Software Foundation, Inc.
|
||||
#
|
||||
# Author: Gregory Casamento <greg.casamento@gmail.com>
|
||||
# Date: July 2009
|
||||
# Author: Gregory Casamento <greg.casamento@gmail.com>,
|
||||
# Stefan Bidigaray <stefanbidi@gmail.com>
|
||||
# Date: July 2009, August 2009
|
||||
#
|
||||
# This file is part of the GNUstep GUI Library.
|
||||
#
|
||||
|
@ -43,11 +44,25 @@ Pop.wav \
|
|||
Sosumi.wav \
|
||||
Tink.wav
|
||||
|
||||
BUNDLE_NAME = Sndfile AudioOutput
|
||||
BUNDLE_EXTENSION = .nssound
|
||||
|
||||
OBJCFLAGS += -Wall -I../Headers/Additions
|
||||
|
||||
Sndfile_OBJC_FILES = SndfileSource.m
|
||||
AudioOutput_OBJC_FILES = AudioOutputSink.m
|
||||
|
||||
Sndfile_PRINCIPAL_CLASS = SndfileSource
|
||||
AudioOutput_PRINCIPAL_CLASS = AudioOutputSink
|
||||
|
||||
Sndfile_BUNDLE_LIBS = -lsndfile
|
||||
AudioOutput_BUNDLE_LIBS = -lao
|
||||
|
||||
-include GNUmakefile.preamble
|
||||
|
||||
-include GNUmakefile.local
|
||||
# We don't actually build anything in this directory so
|
||||
# just include the common makefile rules
|
||||
|
||||
include $(GNUSTEP_MAKEFILES)/rules.make
|
||||
include $(GNUSTEP_MAKEFILES)/bundle.make
|
||||
|
||||
include GNUmakefile.postamble
|
||||
|
|
241
Sounds/SndfileSource.m
Normal file
241
Sounds/SndfileSource.m
Normal file
|
@ -0,0 +1,241 @@
|
|||
/*
|
||||
SndfileSource.m
|
||||
|
||||
Load and read sound data using libsndfile.
|
||||
|
||||
Copyright (C) 2009 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Stefan Bidigaray <stefanbidi@gmail.com>
|
||||
Date: Jun 2009
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, see <http://www.gnu.org/licenses/> or write to the
|
||||
Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/Foundation.h>
|
||||
#include "GNUstepGUI/GSSoundSource.h"
|
||||
#include <sndfile.h>
|
||||
|
||||
@interface SndfileSource : NSObject <GSSoundSource>
|
||||
{
|
||||
NSData *_data;
|
||||
SNDFILE *_snd;
|
||||
SF_INFO _info;
|
||||
|
||||
NSUInteger _curPos;
|
||||
NSTimeInterval _dur;
|
||||
int _encoding;
|
||||
}
|
||||
|
||||
- (NSData *)data;
|
||||
- (NSUInteger)currentPosition;
|
||||
- (void)setCurrentPosition: (NSUInteger)curPos;
|
||||
@end
|
||||
|
||||
/**********************************/
|
||||
/* Sndfile virtual I/O functions. */
|
||||
/**********************************/
|
||||
static inline sf_count_t dataLength (void *user_data)
|
||||
{
|
||||
SndfileSource *snd = (SndfileSource *)user_data;
|
||||
|
||||
return (sf_count_t)[[snd data] length];
|
||||
}
|
||||
|
||||
static inline sf_count_t dataSeek (sf_count_t offset, int whence,
|
||||
void *user_data)
|
||||
{
|
||||
SndfileSource *snd = (SndfileSource *)user_data;
|
||||
|
||||
switch (whence)
|
||||
{
|
||||
case SEEK_SET:
|
||||
break;
|
||||
case SEEK_END:
|
||||
offset = (sf_count_t)[[snd data] length] + offset;
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
offset = (sf_count_t)[snd currentPosition] + offset;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
[snd setCurrentPosition: (NSUInteger)offset];
|
||||
return (sf_count_t)[snd currentPosition];
|
||||
}
|
||||
|
||||
static inline sf_count_t dataRead (void *ptr, sf_count_t count,
|
||||
void *user_data)
|
||||
{
|
||||
NSUInteger newPos;
|
||||
NSRange range;
|
||||
SndfileSource *snd = (SndfileSource *)user_data;
|
||||
|
||||
// Can't read more data that we have available...
|
||||
if (([snd currentPosition] + (NSUInteger)count) > [[snd data] length])
|
||||
{
|
||||
count = (sf_count_t)([[snd data] length] - [snd currentPosition]);
|
||||
}
|
||||
|
||||
newPos = [snd currentPosition] + (NSUInteger)count;
|
||||
[[snd data] getBytes: ptr
|
||||
range: NSMakeRange ([snd currentPosition], count)];
|
||||
[snd setCurrentPosition: newPos];
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static inline sf_count_t dataWrite (const void *ptr, sf_count_t count,
|
||||
void *user_data)
|
||||
{
|
||||
/* FIXME: No write support... do we even need it? */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline sf_count_t dataTell (void *user_data)
|
||||
{
|
||||
SndfileSource *snd = (SndfileSource *)user_data;
|
||||
return (sf_count_t)[snd currentPosition];
|
||||
}
|
||||
|
||||
// The libsndfile virtual I/O function structure
|
||||
static SF_VIRTUAL_IO dataIO = { (sf_vio_get_filelen)dataLength,
|
||||
(sf_vio_seek)dataSeek,
|
||||
(sf_vio_read)dataRead,
|
||||
(sf_vio_write)dataWrite,
|
||||
(sf_vio_tell)dataTell };
|
||||
/**********************************/
|
||||
|
||||
@implementation SndfileSource
|
||||
|
||||
+ (NSArray *)soundUnfilteredFileTypes
|
||||
{
|
||||
return [NSArray arrayWithObjects: @"wav", @"au", @"snd", @"aif", @"aiff",
|
||||
@"aifc", @"paf", @"sf", @"voc", @"w64", @"mat", @"mat4", @"mat5",
|
||||
@"pcf", @"xi", @"caf", @"sd2", @"iff", @"flac", @"ogg", @"oga",
|
||||
nil];
|
||||
}
|
||||
+ (NSArray *)soundUnfilteredTypes
|
||||
{
|
||||
/* FIXME: I'm not sure what the UTI for all the types above are. */
|
||||
return [NSArray arrayWithObjects: @"com.microsoft.waveform-audio",
|
||||
@"public.ulaw-audio", @"public.aiff-audio", @"public.aifc-audio",
|
||||
@"com.apple.coreaudio-format", @"com.digidesign.sd2-audio",
|
||||
/* FIXME: are these right? */
|
||||
@"org.xiph.flac-audio", @"org.xiph.vorbis-audio", nil];
|
||||
}
|
||||
+ (BOOL)canInitWithData: (NSData *)data
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
TEST_RELEASE (_data);
|
||||
sf_close (_snd);
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (id)initWithData: (NSData *)data
|
||||
{
|
||||
self = [super init];
|
||||
if (self == nil)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
_data = data;
|
||||
RETAIN(_data);
|
||||
|
||||
_info.format = 0;
|
||||
_snd = sf_open_virtual (&dataIO, SFM_READ, &_info, self);
|
||||
if (_snd == NULL)
|
||||
{
|
||||
DESTROY(self);
|
||||
return nil;
|
||||
}
|
||||
|
||||
// Setup immutable values...
|
||||
/* FIXME: support multiple types */
|
||||
_encoding = GSSoundFormatPCM16;
|
||||
_dur = (double)_info.frames / (double)_info.samplerate;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSUInteger)readBytes: (void *)bytes length: (NSUInteger)length
|
||||
{
|
||||
return (NSUInteger) (sf_read_short (_snd, bytes, (length>>1))<<1);
|
||||
}
|
||||
|
||||
- (NSTimeInterval)duration
|
||||
{
|
||||
return _dur;
|
||||
}
|
||||
|
||||
- (void)setCurrentTime: (NSTimeInterval)currentTime
|
||||
{
|
||||
sf_count_t frames = (sf_count_t)((double)_info.samplerate * currentTime);
|
||||
sf_seek (_snd, frames, SEEK_SET);
|
||||
}
|
||||
- (NSTimeInterval)currentTime
|
||||
{
|
||||
sf_count_t frames;
|
||||
frames = sf_seek (_snd, 0, SEEK_CUR);
|
||||
return (NSTimeInterval)((double)frames / (double)_info.samplerate);
|
||||
}
|
||||
|
||||
- (int)encoding
|
||||
{
|
||||
return _encoding;
|
||||
}
|
||||
|
||||
- (NSUInteger)channelCount
|
||||
{
|
||||
return (NSUInteger)_info.channels;
|
||||
}
|
||||
|
||||
- (NSUInteger)sampleRate;
|
||||
{
|
||||
return (NSUInteger)_info.samplerate;
|
||||
}
|
||||
|
||||
- (NSByteOrder)byteOrder
|
||||
{
|
||||
// Equivalent to sending native byte order...
|
||||
// Sndfile always reads as native format.
|
||||
return NS_UnknownByteOrder;
|
||||
}
|
||||
|
||||
- (NSData *)data
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
- (NSUInteger)currentPosition
|
||||
{
|
||||
return _curPos;
|
||||
}
|
||||
|
||||
- (void)setCurrentPosition: (NSUInteger)curPos
|
||||
{
|
||||
_curPos = curPos;
|
||||
}
|
||||
|
||||
@end
|
|
@ -432,7 +432,9 @@ GSPrintOperation.h \
|
|||
GSEPSPrintOperation.h \
|
||||
GSPDFPrintOperation.h \
|
||||
GSModelLoaderFactory.h \
|
||||
GSInstantiator.h
|
||||
GSInstantiator.h \
|
||||
GSSoundSink.h \
|
||||
GSSoundSource.h
|
||||
|
||||
libgnustep-gui_HEADER_FILES = ${GUI_HEADERS}
|
||||
|
||||
|
|
804
Source/NSSound.m
804
Source/NSSound.m
File diff suppressed because it is too large
Load diff
|
@ -28,7 +28,7 @@ include ../config.make
|
|||
|
||||
include ../Version
|
||||
|
||||
SUBPROJECTS = $(BUILD_GSND) $(BUILD_SPEECH)
|
||||
SUBPROJECTS = $(BUILD_SPEECH)
|
||||
TOOL_NAME = make_services set_show_service gopen gclose gcloseall
|
||||
SERVICE_NAME = GSspell
|
||||
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
#
|
||||
# Tools level makefile for gsnd
|
||||
#
|
||||
# Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is part of the GNUstep GUI Library.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; see the file COPYING.LIB.
|
||||
# If not, see <http://www.gnu.org/licenses/> or write to the
|
||||
# Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
||||
# Boston, MA 02110-1301, USA.
|
||||
|
||||
PACKAGE_NAME = gnustep-gui
|
||||
include $(GNUSTEP_MAKEFILES)/common.make
|
||||
|
||||
# The applications to be compiled
|
||||
TOOL_NAME = gnustep_sndd
|
||||
|
||||
# The source files to be compiled
|
||||
gnustep_sndd_OBJC_FILES = gsnd.m
|
||||
|
||||
gnustep_sndd_TOOL_LIBS = -lportaudio
|
||||
|
||||
-include GNUmakefile.preamble
|
||||
|
||||
-include GNUmakefile.local
|
||||
|
||||
include $(GNUSTEP_MAKEFILES)/tool.make
|
||||
|
||||
-include GNUmakefile.postamble
|
|
@ -1,47 +0,0 @@
|
|||
#
|
||||
# Makefile.postamble
|
||||
#
|
||||
# Project specific makefile rules
|
||||
#
|
||||
# Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
#
|
||||
# Uncomment the targets you want.
|
||||
# The double colons (::) are important, do not make them single colons
|
||||
# otherwise the normal makefile rules will not be performed.
|
||||
#
|
||||
|
||||
# Things to do before compiling
|
||||
#before-all::
|
||||
|
||||
# Things to do after compiling
|
||||
# after-all::
|
||||
|
||||
# Things to do before installing
|
||||
#before-install::
|
||||
|
||||
# Things to do after installing
|
||||
# after-install::
|
||||
|
||||
# Things to do before uninstalling
|
||||
# before-uninstall::
|
||||
|
||||
# Things to do after uninstalling
|
||||
# after-uninstall::
|
||||
|
||||
# Things to do before cleaning
|
||||
# before-clean::
|
||||
|
||||
# Things to do after cleaning
|
||||
# after-clean::
|
||||
|
||||
# Things to do before distcleaning
|
||||
# before-distclean::
|
||||
|
||||
# Things to do after distcleaning
|
||||
#after-distclean::
|
||||
|
||||
# Things to do before checking
|
||||
# before-check::
|
||||
|
||||
# Things to do after checking
|
||||
# after-check::
|
|
@ -1,42 +0,0 @@
|
|||
#
|
||||
# Makefile.preamble
|
||||
#
|
||||
# Project specific makefile variables, and additional
|
||||
#
|
||||
# Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
#
|
||||
# Do not put any Makefile rules in this file, instead they should
|
||||
# be put into Makefile.postamble.
|
||||
#
|
||||
|
||||
#
|
||||
# Flags dealing with compiling and linking
|
||||
#
|
||||
|
||||
# Additional flags to pass to the preprocessor
|
||||
#ADDITIONAL_CPPFLAGS +=
|
||||
|
||||
# Additional flags to pass to the Objective-C compiler
|
||||
#ADDITIONAL_OBJCFLAGS +=
|
||||
|
||||
# Additional flags to pass to the C compiler
|
||||
#ADDITIONAL_CFLAGS +=
|
||||
|
||||
# Additional include directories the compiler should search
|
||||
#ADDITIONAL_INCLUDE_DIRS +=
|
||||
|
||||
# Additional LDFLAGS to pass to the linker
|
||||
#ADDITIONAL_LDFLAGS +=
|
||||
|
||||
# Additional library directories the linker should search
|
||||
# ADDITIONAL_LIB_DIRS += -L../Source/$(GNUSTEP_OBJ_DIR)
|
||||
|
||||
# Additional libraries when linking applications
|
||||
#ADDITIONAL_TOOL_LIBS +=
|
||||
|
||||
#
|
||||
# Flags dealing with installing and uninstalling
|
||||
#
|
||||
|
||||
# Additional directories to be created during installation
|
||||
#ADDITIONAL_INSTALL_DIRS +=
|
1424
Tools/gsnd/gsnd.m
1424
Tools/gsnd/gsnd.m
File diff suppressed because it is too large
Load diff
26
configure.ac
26
configure.ac
|
@ -354,32 +354,8 @@ AC_CHECK_LIB(icns, icns_read_family_from_file)
|
|||
#--------------------------------------------------------------------
|
||||
# NSSound
|
||||
#--------------------------------------------------------------------
|
||||
AC_ARG_ENABLE(gsnd,
|
||||
[ --disable-gsnd Disable gsnd server],,
|
||||
enable_gsnd=yes)
|
||||
BUILD_GSND=
|
||||
|
||||
# This is only for gsnd, so don't add it to LIBS
|
||||
save_LIBS="$LIBS"
|
||||
AC_CHECK_LIB(portaudio, Pa_OpenDefaultStream, have_portaudio=yes, have_portaudio=no)
|
||||
LIBS="$save_LIBS"
|
||||
|
||||
AC_CHECK_LIB(audiofile, afGetVirtualFrameSize)
|
||||
AC_CHECK_HEADERS(portaudio.h audiofile.h)
|
||||
|
||||
AC_MSG_CHECKING(for portaudio version >= 19)
|
||||
have_portaudio19=no
|
||||
if test $ac_cv_header_portaudio_h = yes; then
|
||||
AC_EGREP_HEADER(PaStreamCallback, portaudio.h,
|
||||
have_portaudio19=yes, have_portaudio19=no)
|
||||
fi
|
||||
AC_MSG_RESULT($have_portaudio19)
|
||||
|
||||
if test $have_portaudio19 = yes -a $have_portaudio = yes -a $enable_gsnd = yes; then
|
||||
BUILD_GSND=gsnd
|
||||
fi
|
||||
AC_SUBST(BUILD_GSND)
|
||||
|
||||
# FIXME: Need to check for libao and libsndfile.
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# NSSpeechSynthesizer
|
||||
|
|
Loading…
Reference in a new issue