From 6ead90c0f0e9b9a44c7c1f7137f437faa29fa750 Mon Sep 17 00:00:00 2001 From: tslil clingman <> Date: Sat, 30 Oct 2021 16:54:03 -0400 Subject: Switched to tracking zig-sfml-wrapper as submodule --- src/sfml/audio/SoundBuffer.zig | 79 ------------------------------------------ 1 file changed, 79 deletions(-) delete mode 100644 src/sfml/audio/SoundBuffer.zig (limited to 'src/sfml/audio/SoundBuffer.zig') 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()); -} -- cgit v1.3.1