Example #1
0
        public void Test1()
        {
            int     deviceID     = 0;
            short   channels     = 1;
            int     samplingRate = 4800;
            int     sampleLength = 10;
            var     blockSize    = (samplingRate * sampleLength);
            SPEAKER channelMask  = SPEAKER.FrontLeft | SPEAKER.FrontRight;

            using var loggerFactory = LoggerFactory.Create(builder =>
            {
                builder.AddFilter("Momiji", LogLevel.Debug);
                builder.AddFilter("Microsoft", LogLevel.Warning);
                builder.AddFilter("System", LogLevel.Warning);
                builder.AddConsole();
                builder.AddDebug();
            });
            var counter = new ElapsedTimeCounter();

            using var pcmPool = new BufferPool <PcmBuffer <short> >(1, () => new PcmBuffer <short>(blockSize, 1), loggerFactory);
            {
                try
                {
                    using var test = new WaveOutShort(deviceID, channels, samplingRate, channelMask, loggerFactory, counter, pcmPool);
                    test.Execute(pcmPool.Receive(), default);
                }
                catch (WaveException)
                {
                }
            }
        }
    public WaveOut(
        int deviceID,
        short channels,
        int samplesPerSecond,
        SPEAKER channelMask,
        Guid formatSubType,
        ILoggerFactory loggerFactory,
        ElapsedTimeCounter counter,
        ITargetBlock <PcmBuffer <T> > releaseQueue
        )
    {
        _loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
        _counter       = counter ?? throw new ArgumentNullException(nameof(counter));

        ArgumentNullException.ThrowIfNull(releaseQueue);

        _logger         = _loggerFactory.CreateLogger <WaveOut <T> >();
        _headerPool     = new BufferPool <WaveHeaderBuffer>(1, () => { return(new WaveHeaderBuffer()); }, _loggerFactory);
        _driverCallBack = new PinnedDelegate <DriverCallBack.Proc>(new DriverCallBack.Proc(DriverCallBackProc));

        var format = new WaveFormatExtensible();

        format.wfe.formatType            = WaveFormatEx.FORMAT.EXTENSIBLE;
        format.wfe.channels              = (ushort)channels;
        format.wfe.samplesPerSecond      = (uint)samplesPerSecond;
        format.wfe.bitsPerSample         = (ushort)(SIZE_OF_T * 8);
        format.wfe.blockAlign            = (ushort)(format.wfe.channels * format.wfe.bitsPerSample / 8);
        format.wfe.averageBytesPerSecond = format.wfe.samplesPerSecond * format.wfe.blockAlign;
        format.wfe.size = (ushort)(Marshal.SizeOf <WaveFormatExtensiblePart>());

        format.exp.validBitsPerSample = format.wfe.bitsPerSample;
        format.exp.channelMask        = ToSPEAKER(channelMask);
        format.exp.subFormat          = formatSubType;

        //たまに失敗するので、ピン止めしておく
        using var formatPin = new PinnedBuffer <WaveFormatExtensible>(format);

        var mmResult =
            NativeMethods.waveOutOpen(
                out _handle,
                deviceID,
                ref format,
                _driverCallBack.FunctionPointer,
                IntPtr.Zero,
                (
                    DriverCallBack.TYPE.FUNCTION
                    | DriverCallBack.TYPE.WAVE_FORMAT_DIRECT
                )
                );

        if (mmResult != MMRESULT.NOERROR)
        {
            throw new WaveException(mmResult);
        }

        _releaseAction = new TransformBlock <IntPtr, PcmBuffer <T> >(headerPtr => Unprepare(headerPtr));
        _releaseAction.LinkTo(releaseQueue);
    }
        public bool Rec_Speaker(Survey _surv)
        {
            int surveyID = Convert.ToInt32(_surv.S_ID);
            int Q_ID     = Convert.ToInt32(_surv.ID);

            using (EventrixDBDataContext db = new EventrixDBDataContext())
            {
                try
                {
                    int _query = (from res in db.SPEAKERs
                                  where res.S_Id.Equals(surveyID)
                                  select res).Count();
                    if (_query == 0) //Create New Answer
                    {
                        SPEAKER toinsert = new SPEAKER();
                        toinsert.S_Id = _surv.S_ID;
                        toinsert.Very_Dissatisfied = _surv.veryDissatisfied;
                        toinsert.Dissatisfied      = _surv.Dissatisfied;
                        toinsert.Neutral           = _surv.Neutral;
                        toinsert.Very_Satisfied    = _surv.VerySatisfied;
                        toinsert.Satisfied         = _surv.Satisfied;

                        db.SPEAKERs.InsertOnSubmit(toinsert);
                        db.SubmitChanges();
                        return(true);
                    }
                    else //Update Record
                    {
                        SPEAKER query = (from res in db.SPEAKERs
                                         where res.S_Id.Equals(surveyID)
                                         select res).First();
                        query.Very_Dissatisfied += _surv.veryDissatisfied;
                        query.Dissatisfied      += _surv.Dissatisfied;
                        query.Neutral           += _surv.Neutral;
                        query.Satisfied         += _surv.Satisfied;
                        query.Very_Satisfied    += _surv.VerySatisfied;
                        db.SubmitChanges();
                        return(true);
                    }
                }
                catch (Exception)
                {
                    return(false);
                }
            };
        }
 public WaveOutShort(
     int deviceID,
     short channels,
     int samplesPerSecond,
     SPEAKER channelMask,
     ILoggerFactory loggerFactory,
     ElapsedTimeCounter counter,
     ITargetBlock <PcmBuffer <short> > sourceReleaseQueue
     ) : base(
         deviceID,
         channels,
         samplesPerSecond,
         channelMask,
         new Guid("00000001-0000-0010-8000-00aa00389b71"),
         loggerFactory,
         counter,
         sourceReleaseQueue
         )
 {
 }
 internal static WaveFormatExtensiblePart.SPEAKER ToSPEAKER(SPEAKER speaker)
 {
     WaveFormatExtensiblePart.SPEAKER result = 0;
     result |= speaker.HasFlag(SPEAKER.FrontLeft) ? WaveFormatExtensiblePart.SPEAKER.FRONT_LEFT: 0;
     result |= speaker.HasFlag(SPEAKER.FrontRight) ? WaveFormatExtensiblePart.SPEAKER.FRONT_RIGHT : 0;
     result |= speaker.HasFlag(SPEAKER.FrontCenter) ? WaveFormatExtensiblePart.SPEAKER.FRONT_CENTER : 0;
     result |= speaker.HasFlag(SPEAKER.LowFrequency) ? WaveFormatExtensiblePart.SPEAKER.LOW_FREQUENCY : 0;
     result |= speaker.HasFlag(SPEAKER.BackLeft) ? WaveFormatExtensiblePart.SPEAKER.BACK_LEFT : 0;
     result |= speaker.HasFlag(SPEAKER.BackRight) ? WaveFormatExtensiblePart.SPEAKER.BACK_RIGHT : 0;
     result |= speaker.HasFlag(SPEAKER.FrontLeftOfCenter) ? WaveFormatExtensiblePart.SPEAKER.FRONT_LEFT_OF_CENTER : 0;
     result |= speaker.HasFlag(SPEAKER.FrontRightOfCenter) ? WaveFormatExtensiblePart.SPEAKER.FRONT_RIGHT_OF_CENTER : 0;
     result |= speaker.HasFlag(SPEAKER.BackCenter) ? WaveFormatExtensiblePart.SPEAKER.BACK_CENTER : 0;
     result |= speaker.HasFlag(SPEAKER.SideLeft) ? WaveFormatExtensiblePart.SPEAKER.SIDE_LEFT : 0;
     result |= speaker.HasFlag(SPEAKER.SideRight) ? WaveFormatExtensiblePart.SPEAKER.SIDE_RIGHT : 0;
     result |= speaker.HasFlag(SPEAKER.TopCenter) ? WaveFormatExtensiblePart.SPEAKER.TOP_CENTER : 0;
     result |= speaker.HasFlag(SPEAKER.TopFrontLeft) ? WaveFormatExtensiblePart.SPEAKER.TOP_FRONT_LEFT : 0;
     result |= speaker.HasFlag(SPEAKER.TopFrontCenter) ? WaveFormatExtensiblePart.SPEAKER.TOP_FRONT_CENTER : 0;
     result |= speaker.HasFlag(SPEAKER.TopFrontRight) ? WaveFormatExtensiblePart.SPEAKER.TOP_FRONT_RIGHT : 0;
     result |= speaker.HasFlag(SPEAKER.TopBackLeft) ? WaveFormatExtensiblePart.SPEAKER.TOP_BACK_LEFT : 0;
     result |= speaker.HasFlag(SPEAKER.TopBackCenter) ? WaveFormatExtensiblePart.SPEAKER.TOP_BACK_CENTER : 0;
     result |= speaker.HasFlag(SPEAKER.TopBackRight) ? WaveFormatExtensiblePart.SPEAKER.TOP_BACK_RIGHT : 0;
     return(result);
 }
 public RESULT setSpeakerPosition(SPEAKER speaker, float x, float y, bool active)
 {
     return(FMOD5_System_SetSpeakerPosition(handle, speaker, x, y, active));
 }
Example #7
0
 public RESULT set3DSpeakerPosition(SPEAKER speaker, float x, float y, bool active)
 {
     return FMOD_System_Set3DSpeakerPosition(systemraw, speaker, x, y, (active ? 1 : 0));
 }
Example #8
0
 public RESULT getSpeakerLevels(SPEAKER speaker, float[] levels, int numlevels)
 {
     return(FMOD_Channel_GetSpeakerLevels(channelraw, speaker, levels, numlevels));
 }
Example #9
0
 private static extern RESULT FMOD_Channel_SetSpeakerLevels(IntPtr channel, SPEAKER speaker, float[] levels, int numlevels);
Example #10
0
 public RESULT setSpeakerLevels(SPEAKER speaker, float[] levels, int numlevels)
 {
     return FMOD_Channel_SetSpeakerLevels(channelraw, speaker, levels, numlevels);
 }
Example #11
0
 public RESULT getSpeakerPosition(SPEAKER speaker, out float x, out float y, out bool active)
 {
     return FMOD_System_GetSpeakerPosition(rawPtr, speaker, out x, out y, out active);
 }
Example #12
0
 private static extern RESULT FMOD5_System_SetSpeakerPosition     (IntPtr system, SPEAKER speaker, float x, float y, bool active);
Example #13
0
 private static extern RESULT FMOD_DSPConnection_GetLevels(IntPtr dspconnection, SPEAKER speaker, float[] levels, int numlevels);
Example #14
0
 private static extern RESULT FMOD5_System_GetSpeakerPosition(IntPtr system, SPEAKER speaker, out float x, out float y, out bool active);
Example #15
0
 public RESULT getSpeakerPosition(SPEAKER speaker, out float x, out float y, out bool active)
 {
     return(System.FMOD5_System_GetSpeakerPosition(this.rawPtr, speaker, out x, out y, out active));
 }
Example #16
0
 public RESULT setSpeakerPosition(SPEAKER speaker, float x, float y, bool active)
 {
     return(System.FMOD5_System_SetSpeakerPosition(this.rawPtr, speaker, x, y, active));
 }
Example #17
0
 private static extern RESULT FMOD_Channel_GetSpeakerLevels(IntPtr channel, SPEAKER speaker, [MarshalAs(UnmanagedType.LPArray)] float[] levels, int numlevels);
Example #18
0
 private static extern RESULT FMOD_Channel_SetSpeakerLevels(IntPtr channel, SPEAKER speaker, float[] levels, int numlevels);
Example #19
0
 public RESULT setSpeakerPosition(SPEAKER speaker, float x, float y)
 {
     return FMOD_System_SetSpeakerPosition(systemraw, speaker, x, y);
 }
Example #20
0
 private static extern RESULT FMOD_System_GetSpeakerPosition(IntPtr system, SPEAKER speaker, ref float x, ref float y);
Example #21
0
 public RESULT getLevels(SPEAKER speaker, float[] levels, int numlevels)
 {
     return(DSPConnection.FMOD_DSPConnection_GetLevels(dspconnectionraw, speaker, levels, numlevels));
 }
Example #22
0
 public RESULT setSpeakerPosition(SPEAKER speaker, float x, float y, bool active)
 {
     return FMOD_System_SetSpeakerPosition(rawPtr, speaker, x, y, active);
 }
Example #23
0
 public RESULT setSpeakerActive(SPEAKER speaker, bool active)
 {
     return FMOD_DSP_SetSpeakerActive(dspraw, speaker, (active ? 1 : 0));
 }
Example #24
0
 private static extern RESULT FMOD_System_GetSpeakerPosition     (IntPtr system, SPEAKER speaker, out float x, out float y, out bool active);
Example #25
0
 public RESULT setLevels(SPEAKER speaker, float[] levels, int numlevels)
 {
     return FMOD_DSPConnection_SetLevels(dspconnectionraw, speaker, levels, numlevels);
 }
Example #26
0
 private static extern RESULT FMOD_Channel_GetSpeakerLevels(IntPtr channel, SPEAKER speaker, [MarshalAs(UnmanagedType.LPArray)]float[] levels, int numlevels);
Example #27
0
 private static extern RESULT FMOD_DSPConnection_SetLevels(IntPtr dspconnection, SPEAKER speaker, float[] levels, int numlevels);
Example #28
0
        public RESULT getSpeakerActive(SPEAKER speaker, ref bool active)
        {
            RESULT result;
            int a = 0;

            result = FMOD_DSP_GetSpeakerActive(dspraw, speaker, ref a);

            active = (a != 0);

            return result;
        }
 public RESULT getSpeakerPosition(SPEAKER speaker, out float x, out float y, out bool active)
 {
     return(FMOD5_System_GetSpeakerPosition(handle, speaker, out x, out y, out active));
 }
Example #30
0
 private static extern RESULT FMOD_DSP_SetSpeakerActive(IntPtr dsp, SPEAKER speaker, int active);
Example #31
0
 public RESULT setOutputLevels(int index, SPEAKER speaker, float[] levels, int numlevels)
 {
     return FMOD_DSP_SetOutputLevels(dspraw, index, speaker, levels, numlevels);
 }
Example #32
0
 private static extern RESULT FMOD_DSPConnection_GetLevels(IntPtr dspconnection, SPEAKER speaker, [MarshalAs(UnmanagedType.LPArray)]float[] levels, int numlevels);
Example #33
0
 private static extern RESULT FMOD_DSP_SetOutputLevels(IntPtr dsp, int index, SPEAKER speaker, float[] levels, int numlevels);
Example #34
0
        public RESULT get3DSpeakerPosition(SPEAKER speaker, ref float x, ref float y, ref bool active)
        {
            RESULT result;

            int isactive = 0;

            result = FMOD_System_Get3DSpeakerPosition(systemraw, speaker, ref x, ref y, ref isactive);

            active = (isactive != 0);

            return result;
        }
Example #35
0
 public RESULT getSpeakerPosition(SPEAKER speaker, ref float x, ref float y)
 {
     return FMOD_System_GetSpeakerPosition(systemraw, speaker, ref x, ref y);
 }
Example #36
0
 private static extern RESULT FMOD_System_Set3DSpeakerPosition(IntPtr system, SPEAKER speaker, float x, float y, int active);
Example #37
0
 public RESULT getSpeakerLevels(SPEAKER speaker, float[] levels, int numlevels)
 {
     return FMOD_Channel_GetSpeakerLevels(getRaw(), speaker, levels, numlevels);
 }