Exemple #1
0
 public LameHeaderVersion1(SOUND_INFO soundInfo, MP3_Settings settings)
 {
     #region " Check the input format "
     if (soundInfo.format != ((int)SOUND_FORMAT.WAV | (int)SOUND_FORMAT.PCM_S16))
     {
         throw new InvalidDataException("Wrong format!", new Exception("Only 16 bit uncompressed WAV supported. You gave " + soundInfo.format));
     }
     # endregion
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Lame"/> class.
        /// </summary>
        /// <param name="InputWaveFile">The input wave file.</param>
        /// <param name="settings">The encoding settings.</param>
        public Lame(string InputWaveFile, MP3_Settings settings)
        {
            inputWaveFile = InputWaveFile;

            SOUND_INFO info = new SOUND_INFO();
            GetSoundFileInfo(InputWaveFile, ref info);

            LAME_CONFIG mp3config = new LAME_CONFIG(info, settings);

            if (beInitStream(mp3config, ref Samples, ref outputBufferSize, ref StreamHandle) != LAME_ERR_SUCCESSFUL)
                throw new Exception("Failed to initialize lame!");

            optimalBufferSize = 2 * (int)Samples;
            InputBuffer = new byte[optimalBufferSize];
            OutputBuffer = new byte[OutputBufferSize];
        }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Lame"/> class.
        /// </summary>
        /// <param name="settings">The encoding settings.</param>
        public Lame(MP3_Settings settings, int Channels, int SampleRate)
        {
            SOUND_INFO info = new SOUND_INFO();
            info.format = 0x010002;
            info.samplerate = SampleRate;
            info.channels = Channels;

            LAME_CONFIG mp3config = new LAME_CONFIG(info, settings);

            if (beInitStream(mp3config, ref Samples, ref outputBufferSize, ref StreamHandle) != LAME_ERR_SUCCESSFUL)
                throw new Exception("Failed to initialize lame!");

            optimalBufferSize = 2 * (int)Samples;
            InputBuffer = new byte[optimalBufferSize];
            OutputBuffer = new byte[OutputBufferSize];
        }
Exemple #4
0
 public config(SOUND_INFO soundInfo, MP3_Settings settings)
 {
     lhv1 = new LameHeaderVersion1(soundInfo, settings);
 }
Exemple #5
0
 public LAME_CONFIG(SOUND_INFO soundInfo, MP3_Settings settings)
 {
     dwConfig = BE_CONFIG_LAME;
     union    = new config(soundInfo, settings);
 }
Exemple #6
0
 public SoundInfo(SOUND_INFO info)
 {
     _fmodSoundInfo = info;
 }
Exemple #7
0
            public RESULT getSoundInfo(string key, out SOUND_INFO info)
            {
                SOUND_INFO_INTERNAL internalInfo;

                RESULT result = FMOD_Studio_System_GetSoundInfo(rawPtr, Encoding.UTF8.GetBytes(key + Char.MinValue), out internalInfo);
                if (result != RESULT.OK)
                {
                info = new SOUND_INFO();
                return result;
                }

                internalInfo.assign(out info);

                return result;
            }
Exemple #8
0
            // Helper functions
            public void assign(out SOUND_INFO publicInfo)
            {
                publicInfo = new SOUND_INFO();

                publicInfo.mode = mode;
                publicInfo.exinfo = exinfo;

                // Somewhat hacky: we know the inclusion list always points to subsoundIndex, so recreate it here
                #if NETFX_CORE
                publicInfo.exinfo.inclusionlist = Marshal.AllocHGlobal(Marshal.SizeOf<Int32>());
                #else
                publicInfo.exinfo.inclusionlist = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Int32)));
                #endif
                Marshal.WriteInt32(publicInfo.exinfo.inclusionlist, subsoundIndex);
                publicInfo.exinfo.inclusionlistnum = 1;

                publicInfo.subsoundIndex = subsoundIndex;

                if (name_or_data != IntPtr.Zero)
                {
                int offset;
                int length;

                if ((mode & (MODE.OPENMEMORY | MODE.OPENMEMORY_POINT)) != 0)
                {
                    // OPENMEMORY_POINT won't work, so force it to OPENMEMORY
                    publicInfo.mode = (publicInfo.mode & ~MODE.OPENMEMORY_POINT) | MODE.OPENMEMORY;

                    // We want the data from (name_or_data + offset) to (name_or_data + offset + length)
                    offset = (int)exinfo.fileoffset;

                    // We'll copy the data taking fileoffset into account, so reset it to 0
                    publicInfo.exinfo.fileoffset = 0;

                    length = (int)exinfo.length;
                }
                else
                {
                    offset = 0;
                    length = MarshallingHelper.stringLengthUtf8(name_or_data) + 1;
                }

                publicInfo.name_or_data = new byte[length];
                Marshal.Copy(new IntPtr(name_or_data.ToInt64() + offset), publicInfo.name_or_data, 0, length);
                }
                else
                {
                publicInfo.name_or_data = null;
                }
            }
Exemple #9
0
            public LameHeaderVersion1(SOUND_INFO soundInfo, MP3_Settings settings)
            {
                #region " Check the input format "
                if (soundInfo.format != ((int)SOUND_FORMAT.WAV | (int)SOUND_FORMAT.PCM_S16))
                {
                    throw new InvalidDataException("Wrong format!", new Exception("Only 16 bit uncompressed WAV supported. You gave " + soundInfo.format));
                }
                # endregion

                dwStructVersion = 1;
                dwStructSize = (uint)Marshal.SizeOf(typeof(LAME_CONFIG));

                # region " Check input sample rate "
                switch (soundInfo.samplerate)
                {
                    case 16000:
                    case 22050:
                    case 24000:
                        dwMpegVersion = MPEG2;
                        break;
                    case 32000:
                    case 44100:
                    case 48000:
                        dwMpegVersion = MPEG1;
                        break;
                    default:
                        throw new InvalidDataException("Wrong format!", new Exception("Sample rate " + soundInfo.samplerate + " not supported."));
                }
                # endregion

                dwSampleRate = (uint)soundInfo.samplerate;
                dwReSampleRate = 0;

                # region " Set encoding channels "
                switch (soundInfo.channels)
                {
                    case 1:
                        nMode = MPEG_MODE.MONO;
                        break;
                    case 2:
                        nMode = MPEG_MODE.STEREO;
                        break;
                    default:
                        throw new InvalidDataException("Wrong format!", new Exception("Invalid number of channels:" + soundInfo.channels));
                }
                # endregion
                # region " Check encoding bit rate "
                switch (settings.Bitrate)
                {
                    case 32:
                    case 40:
                    case 48:
                    case 56:
                    case 64:
                    case 80:
                    case 96:
                    case 112:
                    case 128:
                    case 160:
                        break;
                    // Allowed only in MPEG1:
                    case 192:
                    case 224:
                    case 256:
                    case 320:
                        if (dwMpegVersion != MPEG1)
                        {
                            throw new InvalidDataException("Wrong mp3 bit rate!", new Exception("Incompatible bit rate:" + settings.Bitrate));
                        }
                        break;
                    // Allowed only in MPEG2:
                    case 8:
                    case 16:
                    case 24:
                    case 144:
                        if (dwMpegVersion != MPEG2)
                        {
                            throw new InvalidDataException("Wrong mp3 bit rate!", new Exception("Incompatible bit rate:" + settings.Bitrate));
                        }
                        break;
                    default:
                        throw new InvalidDataException("Wrong mp3 bit rate!", new Exception("Can't support bit rate"));
                }
                # endregion

                dwBitrate = settings.Bitrate;
                nPreset = settings.QualityPreset;

                bEnableVBR = settings.VBR_enabled ? 1 : 0;
                dwMaxBitrate = settings.VBR_maxBitrate;
                dwVbrAbr_bps = 0;
                nQuality = 0;
                nVbrMethod = settings.VBR_method;
                nVBRQuality = settings.VBR_Quality;
                bWriteVBRHeader = settings.VBR_WriteHeader ? 1 : 0;

                bOriginal = settings.OriginalBit ? 1 : 0;
                bCopyright = settings.CopyrightBit ? 1 : 0;
                bCRC = settings.CRC_Bit ? 1 : 0;
                bPrivate = settings.PrivatBit ? 1 : 0;

                bNoRes = settings.DisableBitReservoir ? 1 : 0;
                bStrictIso = settings.StrictISOencoding ? 1 : 0;

                dwPsyModel = 0;
                dwEmphasis = 0;
            }
Exemple #10
0
 public LAME_CONFIG(SOUND_INFO soundInfo, MP3_Settings settings)
 {
     dwConfig = BE_CONFIG_LAME;
     union = new config(soundInfo, settings);
 }
Exemple #11
0
 public config(SOUND_INFO soundInfo, MP3_Settings settings)
 {
     lhv1 = new LameHeaderVersion1(soundInfo, settings);
 }