1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
/*
* MonitorWaveReceiver.cs
* Copyright © 2010-2011 kbinani
*
* This file is part of org.kbinani.cadencii.
*
* org.kbinani.cadencii is free software; you can redistribute it and/or
* modify it under the terms of the GPLv3 License.
*
* org.kbinani.cadencii is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#if JAVA
package org.kbinani.cadencii;
import java.awt.*;
import java.util.*;
import org.kbinani.media.*;
#else
using System;
using org.kbinani.java.awt;
using org.kbinani.java.util;
using org.kbinani.media;
namespace org.kbinani.cadencii
{
using boolean = System.Boolean;
#endif
/// <summary>
/// スピーカへの出力を行う波形受信器
/// </summary>
#if JAVA
public class MonitorWaveReceiver extends WaveUnit implements WaveReceiver {
#else
public class MonitorWaveReceiver : WaveUnit, WaveReceiver
{
#endif
private const int BUFLEN = 1024;
private static MonitorWaveReceiver mSingleton = null;
private boolean mFirstCall = true;
private double[] mBufferL = new double[BUFLEN];
private double[] mBufferR = new double[BUFLEN];
private double[] mBuffer2L = new double[BUFLEN];
private double[] mBuffer2R = new double[BUFLEN];
private WaveReceiver mReceiver = null;
private int mVersion = 0;
private int mSampleRate = 44100;
private long mPosition = 0L;
private MonitorWaveReceiver()
{
}
public double getPlayTime()
{
return (double)mPosition / (double)mSampleRate;
}
public static MonitorWaveReceiver getInstance()
{
return mSingleton;
}
public static MonitorWaveReceiver prepareInstance()
{
if ( mSingleton == null ) {
mSingleton = new MonitorWaveReceiver();
}
mSingleton.end();
mSingleton.mFirstCall = true;
mSingleton.mPosition = 0;
return mSingleton;
}
public override void setConfig( String parameter )
{
// do nothing
}
public override int getVersion()
{
return mVersion;
}
public void setReceiver( WaveReceiver r )
{
if ( mReceiver != null ) {
mReceiver.end();
}
mReceiver = r;
}
public void push( double[] l, double[] r, int length )
{
if ( mFirstCall ) {
mSampleRate = mRoot.getSampleRate();
PlaySound.init();
PlaySound.prepare( mSampleRate );
mFirstCall = false;
}
PlaySound.append( l, r, length );
mPosition += length;
if ( mReceiver != null ) {
mReceiver.push( l, r, length );
}
}
public void end()
{
//PlaySound.exitは,特殊扱い.
//pushが終了していても,たいていの場合再生されずにキャッシュが残っているので.
//PlaySound.exit();
PlaySound.waitForExit();
if ( mReceiver != null ) {
mReceiver.end();
}
}
}
#if !JAVA
}
#endif
|