static int prechargerSons() { try { sons = new Dictionary <String, IntPtr>() { // fin de manche { "temps_ecoule", SDL_mixer.Mix_LoadWAV(@"res\sons\temps_ecoule.wav") }, // bonus { "bonus_vitesse_plus", SDL_mixer.Mix_LoadWAV(@"res\sons\bonus\vitesse+.wav") }, { "bonus_vitesse_moins", SDL_mixer.Mix_LoadWAV(@"res\sons\bonus\vitesse-.wav") }, { "bonus_portee_plus", SDL_mixer.Mix_LoadWAV(@"res\sons\bonus\portee+.wav") }, { "bonus_portee_moins", SDL_mixer.Mix_LoadWAV(@"res\sons\bonus\portee-.wav") }, { "bonus_bombe_plus", SDL_mixer.Mix_LoadWAV(@"res\sons\bonus\bombe+.wav") }, { "bonus_bombe_moins", SDL_mixer.Mix_LoadWAV(@"res\sons\bonus\bombe-.wav") }, // explosion { "explosion", SDL_mixer.Mix_LoadWAV(@"res\sons\bombes\explosion.wav") }, // boutons { "clic_bouton", SDL_mixer.Mix_LoadWAV(@"res\sons\clic_bouton.wav") } }; return(0); } catch { return(1); } }
public MixerSound(string wavFile) { mixerChunkPtr = SDL_mixer.Mix_LoadWAV(wavFile); if (mixerChunkPtr == IntPtr.Zero) { throw new MixerException(); } }
public override void load(string path) { sound = SDL_mixer.Mix_LoadWAV(path); if (sound == IntPtr.Zero) { Console.WriteLine($"There was an issue loading the sound. {SDL.SDL_GetError()}"); Environment.Exit(-1); } }
public override Sound GetSound(string fileId, IFileResolver fileResolver) { IntPtr chunk = SDL_mixer.Mix_LoadWAV(fileResolver.Resolve(fileId)); if (!chunk.Equals(IntPtr.Zero)) { return(new SDLSound(fileId, chunk)); } return(null); }
public static Sound Load(string path) { var chunk = SDL_mixer.Mix_LoadWAV(path); if (chunk == IntPtr.Zero) { throw new InvalidOperationException($"Cant load wav '{path}': {SDL.SDL_GetError()}"); } return(new Sound(chunk)); }
/// <summary> /// Loads a sound file from the Assets directory. Supports the following formats: WAV, OGG. /// </summary> /// <param name="path">The path to the sound file, relative to the Assets directory.</param> public static Sound LoadSound(string path) { IntPtr handle = SDL_mixer.Mix_LoadWAV(GetAssetPath(path)); if (handle == IntPtr.Zero) { throw new Exception("Failed to load sound."); } return(new Sound(handle)); }
private void LoadAndPrepareResources() { music_mp3 = SDL_mixer.Mix_LoadMUS("ringtone.mp3"); if (music_mp3 == IntPtr.Zero) { Console.WriteLine("Failed to load mp3! SDL_mixer error {0}", SDL.SDL_GetError()); } SDL_mixer.Mix_PlayMusic(music_mp3, -1); music_wav = SDL_mixer.Mix_LoadWAV("beat.wav"); if (music_wav == IntPtr.Zero) { Console.WriteLine("Failed to load wav! SDL_mixer error {0}", SDL.SDL_GetError()); } font = SDL_ttf.TTF_OpenFont("lazy.ttf", 64); if (font == IntPtr.Zero) { Console.WriteLine("Failed to load lazy font! SDL_ttf Error: {0}", SDL.SDL_GetError()); } //Render text surface var textColor = new SDL.SDL_Color(); var textSurface = SDL_ttf.TTF_RenderText_Solid(font, "Hello SDL2 World!", textColor); if (textSurface == IntPtr.Zero) { Console.WriteLine("Unable to render text surface! SDL_ttf Error: {0}", SDL.SDL_GetError()); } texture_text = SDL.SDL_CreateTextureFromSurface(renderer, textSurface); if (texture_text == IntPtr.Zero) { Console.WriteLine("Unable to create texture from rendered text! SDL Error: {0}", SDL.SDL_GetError()); } s_text = Marshal.PtrToStructure <SDL.SDL_Surface>(textSurface); IntPtr image_png = SDL_image.IMG_Load("transparent.png"); if (image_png == IntPtr.Zero) { Console.WriteLine("Unable to load image! SDL_image Error: {0}", SDL.SDL_GetError()); } s_png = Marshal.PtrToStructure <SDL.SDL_Surface>(image_png); SDL.SDL_SetColorKey(image_png, (int)SDL.SDL_bool.SDL_TRUE, SDL.SDL_MapRGB(s_png.format, 0, 0xFF, 0xFF)); texture_png = SDL.SDL_CreateTextureFromSurface(renderer, image_png); if (texture_png == IntPtr.Zero) { Console.WriteLine("Unable to create texture from png! SDL Error: {0}", SDL.SDL_GetError()); } }
public IntPtr GetAudioChunk(string audioFile) { var audioPath = Path.Combine(AudiosPath, audioFile); if (!AudioChunksByPath.TryGetValue(audioPath, out var audioChunk)) { audioChunk = SDL_mixer.Mix_LoadWAV(audioPath); AudioChunksByPath[audioPath] = audioChunk; } return(audioChunk); }
public static IntPtr Audio(string path) { if (audio == null) { audio = new Dictionary <string, IntPtr>(); } if (!audio.ContainsKey(path)) { var audioPath = LoadPath(path); var newAudio = SDL_mixer.Mix_LoadWAV(Assets.LoadPath(audioPath)); audio.Add(path, newAudio); } return(audio[path]); }
static bool LoadMedia() { //Loading success flag bool success = true; if (!_PromptTexture.LoadFromFile("prompt.png")) { Console.WriteLine("Failed to load!"); success = false; } //Load music _Music = SDL_mixer.Mix_LoadMUS("beat.wav"); if (_Music == IntPtr.Zero) { Console.WriteLine("Failed to load! {0}", SDL.SDL_GetError()); success = false; } //Load sound effects _Scratch = SDL_mixer.Mix_LoadWAV("scratch.wav"); if (_Scratch == IntPtr.Zero) { Console.WriteLine("Failed to load! {0}", SDL.SDL_GetError()); success = false; } _High = SDL_mixer.Mix_LoadWAV("high.wav"); if (_High == IntPtr.Zero) { Console.WriteLine("Failed to load! {0}", SDL.SDL_GetError()); success = false; } _Medium = SDL_mixer.Mix_LoadWAV("medium.wav"); if (_Medium == IntPtr.Zero) { Console.WriteLine("Failed to load! {0}", SDL.SDL_GetError()); success = false; } _Low = SDL_mixer.Mix_LoadWAV("low.wav"); if (_Low == IntPtr.Zero) { Console.WriteLine("Failed to load! {0}", SDL.SDL_GetError()); success = false; } return(success); }
public static void Main() { int audio_rate = 44100; ushort audio_format = SDL.AUDIO_S16SYS; int audio_channels = 2; int audio_buffers = 4096; int audio_volume = SDL_mixer.MIX_MAX_VOLUME; int timeleft = 50; SDL.SDL_Init(SDL.SDL_INIT_AUDIO); if (SDL_mixer.Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) < 0) { return; } else { SDL_mixer.Mix_QuerySpec(out audio_rate, out audio_format, out audio_channels); } SDL_mixer.Mix_AllocateChannels(32); SDL_mixer.Mix_VolumeMusic(audio_volume / 3); System.IntPtr music = SDL_mixer.Mix_LoadMUS("Tetris_theme.ogg"); System.IntPtr wave = SDL_mixer.Mix_LoadWAV("Meow.ogg"); SDL_mixer.Mix_FadeInMusic(music, 1, 2000); while (SDL_mixer.Mix_PlayingMusic() != 0) { SDL.SDL_Delay(100); timeleft--; if (timeleft == 0) { break; } if (timeleft == 25) { SDL_mixer.Mix_PlayChannel(-1, wave, 0); } } SDL_mixer.Mix_FadeOutMusic(2000); SDL_mixer.Mix_FreeMusic(music); SDL_mixer.Mix_FreeChunk(wave); SDL.SDL_Delay(500); SDL_mixer.Mix_CloseAudio(); SDL.SDL_Quit(); }
/** * Used to initialize audio using SDL and SDL_mixer. This handles loading the sound effect WAV * files from disk and initializing the audio channels. */ public void InitializeAudio(Dictionary <SoundEffect, String> soundEffectsFiles = null) { var audioRate = 22050; // 22.05KHz var audioFormat = SDL.AUDIO_S16SYS; // Unsigned 16-bit samples in the system's byte order var audioChannels = 1; // Mono var audioBuffers = 4096; // 4KB var openAudioResult = SDL_mixer.Mix_OpenAudio(audioRate, audioFormat, audioChannels, audioBuffers); if (openAudioResult != 0) { throw new Exception(String.Format("Failure while opening SDL audio mixer. SDL Error: {0}", SDL.SDL_GetError())); } // We'll use 3 channels; see AUDIO_CHANNEL constants. var allocateChannelsResult = SDL_mixer.Mix_AllocateChannels(3); if (allocateChannelsResult == 0) { throw new Exception(String.Format("Failure while allocating SDL audio mixer channels. SDL Error: {0}", SDL.SDL_GetError())); } soundEffects = new Dictionary <SoundEffect, IntPtr>(); foreach (var entry in soundEffectsFiles) { var sfx = entry.Key; var filePath = entry.Value; var pointer = SDL_mixer.Mix_LoadWAV(filePath); if (pointer == null) { throw new Exception(String.Format("Error loading sound {0}. SDL Error: {1}", sfx, SDL.SDL_GetError())); } soundEffects.Add(sfx, pointer); } }
public IntPtr LoadSound(string filepath) { return(SDL_mixer.Mix_LoadWAV(filepath)); }
public WAV(string File) { myPtr = SDL_mixer.Mix_LoadWAV(File); CheckPtr(); }
public static SDL_mixer.Mix_Chunk LoadSound(string snd) { var fn = string.Format("{0}{1}{2}", GlobalMembers.oslink.soundDir, GlobalMembers.oslink.pathSep, snd); return(SDL_mixer.Mix_LoadWAV(fn)); }