diff options
| author | tslil clingman <> | 2021-10-30 16:54:03 -0400 |
|---|---|---|
| committer | tslil clingman <> | 2021-10-30 16:56:41 -0400 |
| commit | 6ead90c0f0e9b9a44c7c1f7137f437faa29fa750 (patch) | |
| tree | 38cbaff4f606689a149865d5708dadac47ee43db /src/sfml/audio | |
| parent | 48dee0817f5fe8c09a085f0150e0c6b4a699ab7c (diff) | |
Switched to tracking zig-sfml-wrapper as submodule
Diffstat (limited to 'src/sfml/audio')
| -rw-r--r-- | src/sfml/audio/Music.zig | 111 | ||||
| -rw-r--r-- | src/sfml/audio/Sound.zig | 107 | ||||
| -rw-r--r-- | src/sfml/audio/SoundBuffer.zig | 79 |
3 files changed, 0 insertions, 297 deletions
diff --git a/src/sfml/audio/Music.zig b/src/sfml/audio/Music.zig deleted file mode 100644 index d55a718..0000000 --- a/src/sfml/audio/Music.zig +++ /dev/null @@ -1,111 +0,0 @@ -//! Streamed music played from an audio file. - -const sf = @import("../sfml.zig"); - -const Music = @This(); - -// Constructor/destructor - -/// Loads music from a file -pub fn createFromFile(path: [:0]const u8) !Music { - var music = sf.c.sfMusic_createFromFile(path); - if (music == null) - return sf.Error.resourceLoadingError; - return Music{ ._ptr = music.? }; -} - -pub const initFromMemory = @compileError("Function is not implemented yet."); -pub const initFromStream = @compileError("Function is not implemented yet."); - -/// Destroys this music object -pub fn destroy(self: *Music) void { - sf.c.sfMusic_destroy(self._ptr); -} - -// Music control functions - -/// Plays the music -pub fn play(self: *Music) void { - sf.c.sfMusic_play(self._ptr); -} -/// Pauses the music -pub fn pause(self: *Music) void { - sf.c.sfMusic_pause(self._ptr); -} -/// Stops the music and resets the player position -pub fn stop(self: *Music) void { - sf.c.sfMusic_stop(self._ptr); -} - -// Getters / Setters - -/// Gets the total duration of the music -pub fn getDuration(self: Music) sf.Time { - return sf.Time._fromCSFML(sf.c.sfMusic_getDuration(self._ptr)); -} - -/// Gets the current stream position of the music -pub fn getPlayingOffset(self: Music) sf.Time { - return sf.Time._fromCSFML(sf.c.sfMusic_getPlayingOffset(self._ptr)); -} -/// Sets the current stream position of the music -pub fn setPlayingOffset(self: *Music, offset: sf.Time) void { - sf.c.sfMusic_setPlayingOffset(self._ptr, offset._toCSFML()); -} - -/// Gets the loop points of the music -pub fn getLoopPoints(self: Music) sf.TimeSpan { - return sf.TimeSpan._fromCSFML(sf.c.sfMusic_getLoopPoints(self._ptr)); -} -/// Gets the loop points of the music -pub fn setLoopPoints(self: *Music, span: sf.TimeSpan) void { - sf.c.sfMusic_setLoopPoints(self._ptr, span._toCSFML()); -} - -/// Tells whether or not this stream is in loop mode -pub fn getLoop(self: Music) bool { - return sf.c.sfMusic_getLoop(self._ptr) != 0; -} -/// Enable or disable auto loop -pub fn setLoop(self: *Music, loop: bool) void { - sf.c.sfMusic_setLoop(self._ptr, @boolToInt(loop)); -} - -/// Sets the pitch of the music -pub fn getPitch(self: Music) f32 { - return sf.c.sfMusic_getPitch(self._ptr); -} -/// Gets the pitch of the music -pub fn setPitch(self: *Music, pitch: f32) void { - sf.c.sfMusic_setPitch(self._ptr, pitch); -} - -/// Sets the volume of the music -pub fn getVolume(self: Music) f32 { - return sf.c.sfMusic_getVolume(self._ptr); -} -/// Gets the volume of the music -pub fn setVolume(self: *Music, volume: f32) void { - sf.c.sfMusic_setVolume(self._ptr, volume); -} - -/// Gets the sample rate of this music -pub fn getSampleRate(self: Music) usize { - return @intCast(usize, sf.c.sfMusic_getSampleRate(self._ptr)); -} - -/// Gets the channel count of the music -pub fn getChannelCount(self: Music) usize { - return @intCast(usize, sf.c.sfMusic_getChannelCount(self._ptr)); -} - -pub const getStatus = @compileError("Function is not implemented yet."); -pub const setRelativeToListener = @compileError("Function is not implemented yet."); -pub const isRelativeToListener = @compileError("Function is not implemented yet."); -pub const setMinDistance = @compileError("Function is not implemented yet."); -pub const setAttenuation = @compileError("Function is not implemented yet."); -pub const getMinDistance = @compileError("Function is not implemented yet."); -pub const getAttenuation = @compileError("Function is not implemented yet."); - -/// Pointer to the csfml music -_ptr: *sf.c.sfMusic, diff --git a/src/sfml/audio/Sound.zig b/src/sfml/audio/Sound.zig deleted file mode 100644 index 92acb46..0000000 --- a/src/sfml/audio/Sound.zig +++ /dev/null @@ -1,107 +0,0 @@ -//! Regular sound that can be played in the audio environment. - -const sf = struct { - pub usingnamespace @import("../sfml.zig"); - pub usingnamespace sf.audio; -}; - -const Sound = @This(); - -// Constructor/destructor - -/// Inits an empty sound -pub fn create() !Sound { - var sound = sf.c.sfSound_create(); - if (sound == null) - return sf.Error.nullptrUnknownReason; - return Sound{ ._ptr = sound.? }; -} - -/// Inits a sound with a SoundBuffer object -pub fn createFromBuffer(buffer: sf.SoundBuffer) !Sound { - var sound = try Sound.create(); - sound.setBuffer(buffer); - return sound; -} - -/// Destroys this sound object -pub fn destroy(self: *Sound) void { - sf.c.sfSound_destroy(self._ptr); -} - -// Sound control functions - -/// Plays the sound -pub fn play(self: *Sound) void { - sf.c.sfSound_play(self._ptr); -} -/// Pauses the sound -pub fn pause(self: *Sound) void { - sf.c.sfSound_pause(self._ptr); -} -/// Stops the sound and resets the player position -pub fn stop(self: *Sound) void { - sf.c.sfSound_stop(self._ptr); -} - -// Getters / Setters - -/// Gets the buffer this sound is attached to -pub fn getBuffer(self: Sound) ?sf.SoundBuffer { - var buf = sf.c.sfSound_getBuffer(self._ptr); - if (buf) |buffer| { - return .{ ._ptr = buffer }; - } else return null; -} - -/// Sets the buffer this sound will play -pub fn setBuffer(self: *Sound, buffer: sf.SoundBuffer) void { - sf.c.sfSound_setBuffer(self._ptr, buffer._ptr); -} - -/// Gets the current playing offset of the sound -pub fn getPlayingOffset(self: Sound) sf.Time { - return sf.Time._fromCSFML(sf.c.sfSound_getPlayingOffset(self._ptr)); -} -/// Sets the current playing offset of the sound -pub fn setPlayingOffset(self: *Sound, offset: sf.Time) void { - sf.c.sfSound_setPlayingOffset(self._ptr, offset._toCSFML()); -} - -/// Tells whether or not this sound is in loop mode -pub fn getLoop(self: Sound) bool { - return sf.c.sfSound_getLoop(self._ptr) != 0; -} -/// Enable or disable auto loop -pub fn setLoop(self: *Sound, loop: bool) void { - sf.c.sfSound_setLoop(self._ptr, @boolToInt(loop)); -} - -/// Sets the pitch of the sound -pub fn getPitch(self: Sound) f32 { - return sf.c.sfSound_getPitch(self._ptr); -} -/// Gets the pitch of the sound -pub fn setPitch(self: *Sound, pitch: f32) void { - sf.c.sfSound_setPitch(self._ptr, pitch); -} - -/// Sets the volume of the sound -pub fn getVolume(self: Sound) f32 { - return sf.c.sfSound_getVolume(self._ptr); -} -/// Gets the volume of the sound -pub fn setVolume(self: *Sound, volume: f32) void { - sf.c.sfSound_setVolume(self._ptr, volume); -} - -pub const getStatus = @compileError("Function is not implemented yet."); -pub const setRelativeToListener = @compileError("Function is not implemented yet."); -pub const isRelativeToListener = @compileError("Function is not implemented yet."); -pub const setMinDistance = @compileError("Function is not implemented yet."); -pub const setAttenuation = @compileError("Function is not implemented yet."); -pub const getMinDistance = @compileError("Function is not implemented yet."); -pub const getAttenuation = @compileError("Function is not implemented yet."); - -/// Pointer to the csfml sound -_ptr: *sf.c.sfSound, diff --git a/src/sfml/audio/SoundBuffer.zig b/src/sfml/audio/SoundBuffer.zig deleted file mode 100644 index 39ed082..0000000 --- a/src/sfml/audio/SoundBuffer.zig +++ /dev/null @@ -1,79 +0,0 @@ -//! Storage for audio samples defining a sound. - -const sf = @import("../sfml.zig"); - -const SoundBuffer = @This(); - -// Constructor/destructor -/// Loads music from a file -pub fn createFromFile(path: [:0]const u8) !SoundBuffer { - var sound = sf.c.sfSoundBuffer_createFromFile(path); - if (sound == null) - return sf.Error.resourceLoadingError; - return SoundBuffer{ ._ptr = sound.? }; -} -/// Creates a sound buffer from sample data -pub fn createFromSamples(samples: []const i16, channel_count: usize, sample_rate: usize) !SoundBuffer { - var sound = sf.c.sfSoundBuffer_createFromSamples(@ptrCast([*c]const c_short, samples.ptr), samples.len, @intCast(c_uint, channel_count), @intCast(c_uint, sample_rate)); - if (sound == null) - return sf.Error.resourceLoadingError; - return SoundBuffer{ ._ptr = sound.? }; -} - -pub const initFromMemory = @compileError("Function is not implemented yet."); -pub const initFromStream = @compileError("Function is not implemented yet."); - -/// Destroys this music object -pub fn destroy(self: *SoundBuffer) void { - sf.c.sfSoundBuffer_destroy(self._ptr); -} - -// Getters / Setters - -/// Gets the duration of the sound -pub fn getDuration(self: SoundBuffer) sf.system.Time { - return sf.system.Time._fromCSFML(sf.c.sfSoundBuffer_getDuration(self._ptr)); -} - -/// Gets the sample count of this sound -pub fn getSampleCount(self: SoundBuffer) usize { - return @intCast(usize, sf.c.sfSoundBuffer_getSampleCount(self._ptr)); -} - -/// Gets the sample rate of this sound (n° of samples per second, often 44100) -pub fn getSampleRate(self: SoundBuffer) usize { - return @intCast(usize, sf.c.sfSoundBuffer_getSampleRate(self._ptr)); -} - -/// Gets the channel count (2 is stereo for instance) -pub fn getChannelCount(self: SoundBuffer) usize { - return @intCast(usize, sf.c.sfSoundBuffer_getChannelCount(self._ptr)); -} - -// Misc - -/// Save the sound buffer to an audio file -pub fn saveToFile(self: SoundBuffer, path: [:0]const u8) !void { - if (sf.c.sfSoundBuffer_saveToFile(self._ptr, path) != 1) - return sf.Error.savingInFileFailed; -} - -/// Pointer to the csfml texture -_ptr: *sf.c.sfSoundBuffer, - -test "sound buffer: sane getter and setters" { - const std = @import("std"); - const tst = std.testing; - const allocator = std.heap.page_allocator; - - var samples = try allocator.alloc(i16, 44100 * 3); - defer allocator.free(samples); - - var buffer = try SoundBuffer.createFromSamples(samples, 1, 44100); - defer buffer.destroy(); - - try tst.expectApproxEqAbs(@as(f32, 3), buffer.getDuration().asSeconds(), 0.001); - try tst.expectEqual(@as(usize, 44100 * 3), buffer.getSampleCount()); - try tst.expectEqual(@as(usize, 44100), buffer.getSampleRate()); - try tst.expectEqual(@as(usize, 1), buffer.getChannelCount()); -} |
