1 /* 2 * DSFML - The Simple and Fast Multimedia Library for D 3 * 4 * Copyright (c) 2013 - 2018 Jeremy DeHaan (dehaan.jeremiah@gmail.com) 5 * 6 * This software is provided 'as-is', without any express or implied warranty. 7 * In no event will the authors be held liable for any damages arising from the 8 * use of this software. 9 * 10 * Permission is granted to anyone to use this software for any purpose, 11 * including commercial applications, and to alter it and redistribute it 12 * freely, subject to the following restrictions: 13 * 14 * 1. The origin of this software must not be misrepresented; you must not claim 15 * that you wrote the original software. If you use this software in a product, 16 * an acknowledgment in the product documentation would be appreciated but is 17 * not required. 18 * 19 * 2. Altered source versions must be plainly marked as such, and must not be 20 * misrepresented as being the original software. 21 * 22 * 3. This notice may not be removed or altered from any source distribution 23 * 24 * 25 * DSFML is based on SFML (Copyright Laurent Gomila) 26 */ 27 28 /** 29 * This class encodes audio samples to a sound file. 30 * 31 * It is used internally by higher-level classes such as $(SOUNDBUFFER_LINK), 32 * but can also be useful if you want to create audio files from custom data 33 * sources, like generated audio samples. 34 * 35 * Example: 36 * --- 37 * // Create a sound file, ogg/vorbis format, 44100 Hz, stereo 38 * auto file = new OutputSoundFile(); 39 * if (!file.openFromFile("music.ogg", 44100, 2)) 40 * { 41 * //error 42 * } 43 * 44 * while (...) 45 * { 46 * // Read or generate audio samples from your custom source 47 * short[] samples = ...; 48 * 49 * // Write them to the file 50 * file.write(samples); 51 * } 52 * --- 53 * 54 * See_Also: 55 * $(INPUTSOUNDFILE_LINK) 56 */ 57 module nudsfml.audio.outputsoundfile; 58 59 import bindbc.sfml.audio; 60 61 import std.string; 62 import nudsfml.system.err; 63 64 /** 65 * Provide write access to sound files. 66 */ 67 class OutputSoundFile { 68 //private sfOutputSoundFile* m_soundFile; 69 70 /// Default constructor. 71 this() { 72 //m_soundFile = null; // sfOutputSoundFile_create(); 73 } 74 75 /// Destructor. 76 ~this() { 77 import nudsfml.system.config : destructorOutput; 78 79 mixin(destructorOutput); 80 /*if(m_soundFile !is null) { 81 sfOutputSoundFile_destroy(m_soundFile); 82 }*/ 83 } 84 85 /** 86 * Open the sound file from the disk for writing. 87 * 88 * The supported audio formats are: WAV, OGG/Vorbis, FLAC. 89 * 90 * Params: 91 * filename = Path of the sound file to load 92 * sampleRate = Sample rate of the sound 93 * channelCount = Number of channels in the sound 94 * 95 * Returns: true if the file was successfully opened. 96 */ 97 bool openFromFile(const(char)[] filename, uint sampleRate, uint channelCount) { 98 return false; // sfOutputSoundFile_openFromFile(m_soundFile, filename.ptr, filename.length,channelCount,sampleRate); 99 } 100 101 /** 102 * Write audio samples to the file. 103 * 104 * Params: 105 * samples = array of samples to write 106 */ 107 void write(const(short)[] samples) { 108 //sfOutputSoundFile_write(m_soundFile, samples.ptr, samples.length); 109 } 110 111 }