Skip to content

Commit

Permalink
Added openal auido manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Tornado-Technology committed Jul 13, 2024
1 parent 7a281a2 commit dff891b
Show file tree
Hide file tree
Showing 15 changed files with 412 additions and 24 deletions.
44 changes: 44 additions & 0 deletions Hypercube.Client/Audio/AudioId.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace Hypercube.Client.Audio;

public readonly struct AudioId(int value) : IEquatable<AudioId>
{
public static readonly AudioId Invalid = new(-1);
public static readonly AudioId Zero = new(0);

public readonly int Value = value;

public bool Equals(AudioId other)
{
return Value == other.Value;
}

public override bool Equals(object? obj)
{
return obj is AudioId id && Equals(id);
}

public static bool operator ==(AudioId a, AudioId b)
{
return a.Equals(b);
}

public static bool operator !=(AudioId a, AudioId b)
{
return !a.Equals(b);
}

public static implicit operator int(AudioId id)
{
return id.Value;
}

public override int GetHashCode()
{
return Value;
}

public override string ToString()
{
return $"audio({Value})";
}
}
3 changes: 3 additions & 0 deletions Hypercube.Client/Audio/AudioSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace Hypercube.Client.Audio;

public readonly struct AudioSettings;
13 changes: 13 additions & 0 deletions Hypercube.Client/Audio/AudioStream.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Hypercube.Client.Audio;

public sealed class AudioStream
{
public readonly AudioId Id;
public readonly TimeSpan Length;

public AudioStream(AudioId id, TimeSpan length)
{
Id = id;
Length = length;
}
}
3 changes: 3 additions & 0 deletions Hypercube.Client/Audio/IAudioData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
public interface IAudioData
{
AudioFormat Format { get; }
ReadOnlyMemory<byte> Data { get; }
int SampleRate { get; }
TimeSpan Length { get; }
}
9 changes: 5 additions & 4 deletions Hypercube.Client/Audio/IAudioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ namespace Hypercube.Client.Audio;

public interface IAudioManager
{
IAudio CreateAudio(ResourcePath path, IAudioSettings settings);
IAudio CreateAudio(Stream stream, IAudioSettings settings);

IAudio GetAudio(ResourcePath path, IAudioSettings settings);
IAudioSource CreateSource(ResourcePath path, AudioSettings settings);
IAudioSource CreateSource(AudioStream stream);
AudioStream GetAudio(ResourcePath path, AudioSettings settings);

void Initialize();

/// <summary>
/// Pause all audio sources.
Expand Down
6 changes: 0 additions & 6 deletions Hypercube.Client/Audio/IAudioSettings.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
namespace Hypercube.Client.Audio;

public interface IAudio : IDisposable
public interface IAudioSource : IDisposable
{
IAudioGroup? Group { get; }

bool Looping { get; }
bool Playing { get; }

float Pitch { get; }
float Gain { get; }
bool Looping { get; set; }
float Pitch { get; set; }
float Gain { get; set; }

void Start();
void Stop();
Expand Down
14 changes: 8 additions & 6 deletions Hypercube.Client/Audio/Reader/Wav/AudioWavData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,28 @@
public readonly struct AudioWavData : IAudioData
{
public AudioFormat Format { get; }
public ReadOnlyMemory<byte> Data { get; }
public int SampleRate { get; }
public TimeSpan Length { get; }

public readonly short FormatType;
public readonly short Channels;
public readonly int SampleRate;
public readonly int ByteRate;
public readonly short BlockAlign;
public readonly short BitsPerSample;
public readonly byte[] Data;

public AudioWavData(short formatType, short channels, int sampleRate, int byteRate, short blockAlign, short bitsPerSample, byte[] data)
public AudioWavData(short formatType, short channels, int sampleRate, int byteRate, short blockAlign, short bitsPerSample, ReadOnlyMemory<byte> data)
{
Format = GetFormat(channels, byteRate);
Format = GetFormat(channels, bitsPerSample);
Data = data;
SampleRate = sampleRate;
Length = TimeSpan.FromSeconds(data.Length / (double) blockAlign / sampleRate);

FormatType = formatType;
Channels = channels;
SampleRate = sampleRate;
ByteRate = byteRate;
BlockAlign = blockAlign;
BitsPerSample = bitsPerSample;
Data = data;
}

public override string ToString()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Hypercube.Client.Audio.Realisations.OpenAL;

public static class ContextExtension
{
public const string Eax = "EAX2.0";
public const string Efx = "ALC_EXT_EFX";
}
Loading

0 comments on commit dff891b

Please sign in to comment.