Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,3 +1,18 @@
|
|||
{{omit from|AWK}}
|
||||
{{omit from|Brlcad}}
|
||||
{{omit from|HTML}}
|
||||
{{omit from|Logtalk}}
|
||||
{{omit from|Lotus 123 Macro Scripting}}
|
||||
{{omit from|Maxima}}
|
||||
{{omit from|ML/I}}
|
||||
{{omit from|Openscad}}
|
||||
{{omit from|PARI/GP}}
|
||||
{{omit from|TI-83 BASIC}}
|
||||
{{omit from|TPP}}
|
||||
{{omit from|zkl}}
|
||||
|
||||
Record a monophonic 16-bit PCM sound into either memory space, a file or array.
|
||||
|
||||
(This task neglects to specify the sample rate, and whether to use signed samples. The programs in this page might use signed 16-bit or unsigned 16-bit samples, at 8000 Hz, 44100 Hz, or any other sample rate. Therefore, these programs might not record sound in the same format.)
|
||||
(This task neglects to specify the sample rate, and whether to use signed samples.
|
||||
The programs in this page might use signed 16-bit or unsigned 16-bit samples, at 8000 Hz, 44100 Hz, or any other sample rate.
|
||||
Therefore, these programs might not record sound in the same format.)
|
||||
|
|
|
|||
4
Task/Record-sound/00META.yaml
Normal file
4
Task/Record-sound/00META.yaml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
category:
|
||||
- Temporal media
|
||||
note: Sound
|
||||
93
Task/Record-sound/C++/record-sound.cpp
Normal file
93
Task/Record-sound/C++/record-sound.cpp
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
#include <windows.h>
|
||||
#include <mmsystem.h>
|
||||
|
||||
#pragma comment ( lib, "winmm.lib" )
|
||||
using namespace std;
|
||||
|
||||
class recorder
|
||||
{
|
||||
public:
|
||||
void start()
|
||||
{
|
||||
paused = rec = false; action = "IDLE";
|
||||
while( true )
|
||||
{
|
||||
cout << endl << "==" << action << "==" << endl << endl;
|
||||
cout << "1) Record" << endl << "2) Play" << endl << "3) Pause" << endl << "4) Stop" << endl << "5) Quit" << endl;
|
||||
char c; cin >> c;
|
||||
if( c > '0' && c < '6' )
|
||||
{
|
||||
switch( c )
|
||||
{
|
||||
case '1': record(); break;
|
||||
case '2': play(); break;
|
||||
case '3': pause(); break;
|
||||
case '4': stop(); break;
|
||||
case '5': stop(); return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private:
|
||||
void record()
|
||||
{
|
||||
if( mciExecute( "open new type waveaudio alias my_sound") )
|
||||
{
|
||||
mciExecute( "record my_sound" );
|
||||
action = "RECORDING"; rec = true;
|
||||
}
|
||||
}
|
||||
void play()
|
||||
{
|
||||
if( paused )
|
||||
mciExecute( "play my_sound" );
|
||||
else
|
||||
if( mciExecute( "open tmp.wav alias my_sound" ) )
|
||||
mciExecute( "play my_sound" );
|
||||
|
||||
action = "PLAYING";
|
||||
paused = false;
|
||||
}
|
||||
void pause()
|
||||
{
|
||||
if( rec ) return;
|
||||
mciExecute( "pause my_sound" );
|
||||
paused = true; action = "PAUSED";
|
||||
}
|
||||
void stop()
|
||||
{
|
||||
if( rec )
|
||||
{
|
||||
mciExecute( "stop my_sound" );
|
||||
mciExecute( "save my_sound tmp.wav" );
|
||||
mciExecute( "close my_sound" );
|
||||
action = "IDLE"; rec = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
mciExecute( "stop my_sound" );
|
||||
mciExecute( "close my_sound" );
|
||||
action = "IDLE";
|
||||
}
|
||||
}
|
||||
bool mciExecute( string cmd )
|
||||
{
|
||||
if( mciSendString( cmd.c_str(), NULL, 0, NULL ) )
|
||||
{
|
||||
cout << "Can't do this: " << cmd << endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool paused, rec;
|
||||
string action;
|
||||
};
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
recorder r; r.start();
|
||||
return 0;
|
||||
}
|
||||
51
Task/Record-sound/Scala/record-sound.scala
Normal file
51
Task/Record-sound/Scala/record-sound.scala
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import java.io.{File, IOException}
|
||||
import javax.sound.sampled.{AudioFileFormat, AudioFormat, AudioInputStream}
|
||||
import javax.sound.sampled.{AudioSystem, DataLine, LineUnavailableException, TargetDataLine}
|
||||
|
||||
object SoundRecorder extends App {
|
||||
// record duration, in milliseconds
|
||||
final val RECORD_TIME = 60000 // 1 minute
|
||||
|
||||
// path and format of the wav file
|
||||
val (wavFile, fileType) = (new File("RecordAudio.wav"), AudioFileFormat.Type.WAVE)
|
||||
val format = new AudioFormat(/*sampleRate =*/ 16000f,
|
||||
/*sampleSizeInBits =*/ 16,
|
||||
/*channels =*/ 2,
|
||||
/*signed =*/ true,
|
||||
/*bigEndian =*/ true)
|
||||
|
||||
val info = new DataLine.Info(classOf[TargetDataLine], format)
|
||||
val line: TargetDataLine = AudioSystem.getLine(info).asInstanceOf[TargetDataLine]
|
||||
|
||||
// Entry to run the program
|
||||
|
||||
// Creates a new thread that waits for a specified of time before stopping
|
||||
new Thread(new Runnable() {
|
||||
def run() {
|
||||
try {
|
||||
Thread.sleep(RECORD_TIME)
|
||||
} catch {
|
||||
case ex: InterruptedException => ex.printStackTrace()
|
||||
}
|
||||
finally {
|
||||
line.stop()
|
||||
line.close()
|
||||
}
|
||||
println("Finished")
|
||||
}
|
||||
}).start()
|
||||
|
||||
//Captures the sound and record into a WAV file
|
||||
try {
|
||||
// checks if system supports the data line
|
||||
if (AudioSystem.isLineSupported(info)) {
|
||||
line.open(format)
|
||||
line.start() // start capturing
|
||||
println("Recording started")
|
||||
AudioSystem.write(new AudioInputStream(line), fileType, wavFile)
|
||||
} else println("Line not supported")
|
||||
} catch {
|
||||
case ex: LineUnavailableException => ex.printStackTrace()
|
||||
case ioe: IOException => ioe.printStackTrace()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue