Commit d37d4a2f authored by Mikhail Karpenko's avatar Mikhail Karpenko

Update GUI to record sound

parent 74b40b6b
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <ctype.h> #include <ctype.h>
#include <elphel/ahci_cmd.h> #include <elphel/ahci_cmd.h>
#include "camogm.h"
#include "camogm_ogm.h" #include "camogm_ogm.h"
#include "camogm_jpeg.h" #include "camogm_jpeg.h"
#include "camogm_mov.h" #include "camogm_mov.h"
...@@ -288,6 +289,7 @@ void camogm_init(camogm_state *state, char *pipe_name, uint16_t port_num) ...@@ -288,6 +289,7 @@ void camogm_init(camogm_state *state, char *pipe_name, uint16_t port_num)
state->audio.set_audio_channels = SAMPLE_CHANNELS; state->audio.set_audio_channels = SAMPLE_CHANNELS;
state->audio.set_audio_rate = SAMPLE_RATE; state->audio.set_audio_rate = SAMPLE_RATE;
state->audio.set_audio_volume = DEFAULT_AUDIO_VOLUME; state->audio.set_audio_volume = DEFAULT_AUDIO_VOLUME;
state->audio.audio_volume = DEFAULT_AUDIO_VOLUME;
state->audio.get_fpga_time = get_fpga_time_w; state->audio.get_fpga_time = get_fpga_time_w;
} }
...@@ -1042,16 +1044,21 @@ static void camogm_set_audio_state(camogm_state *state, char *args) ...@@ -1042,16 +1044,21 @@ static void camogm_set_audio_state(camogm_state *state, char *args)
} }
} }
/** @brief Set audio volume */ /** @brief Set audio volume
* @param[in] state a pointer to a structure containing current state
* @param[in] args string containing audio volume, in percent
*/
static void camogm_set_audio_volume(camogm_state *state, char *args) static void camogm_set_audio_volume(camogm_state *state, char *args)
{ {
int vol = atoi(args); int vol = atoi(args);
if (vol > 65535) if (vol > 100)
vol = 65535; vol = 100;
if (vol < 0) if (vol < 0)
vol = 0; vol = 0;
state->audio.set_audio_volume = vol; state->audio.set_audio_volume = (vol * DEFAULT_AUDIO_VOLUME) / 100;
if (state->prog_state == STATE_STOPPED)
state->audio.audio_volume = state->audio.set_audio_volume;
} }
/** @brief Set audio sample rate and number of channels */ /** @brief Set audio sample rate and number of channels */
...@@ -1113,6 +1120,7 @@ void camogm_status(camogm_state *state, char * fn, int xml) ...@@ -1113,6 +1120,7 @@ void camogm_status(camogm_state *state, char * fn, int xml)
int _sec_skip = 0; int _sec_skip = 0;
char *_kml_enable, *_kml_used, *_kml_height_mode; char *_kml_enable, *_kml_used, *_kml_height_mode;
char *_audio_en; char *_audio_en;
int _audio_vol, _format;
unsigned int _percent_done; unsigned int _percent_done;
off_t save_p; off_t save_p;
...@@ -1184,9 +1192,13 @@ void camogm_status(camogm_state *state, char * fn, int xml) ...@@ -1184,9 +1192,13 @@ void camogm_status(camogm_state *state, char * fn, int xml)
default: default:
_state = "stopped"; _state = "stopped";
} }
_output_format = state->format ? ((state->format == CAMOGM_FORMAT_OGM) ? "ogm" : if (state->format == state->set_format)
((state->format == CAMOGM_FORMAT_JPEG) ? "jpeg" : _format = state->format;
((state->format == CAMOGM_FORMAT_MOV) ? "mov" : else
_format = state->set_format;
_output_format = _format ? ((_format == CAMOGM_FORMAT_OGM) ? "ogm" :
((_format == CAMOGM_FORMAT_JPEG) ? "jpeg" :
((_format == CAMOGM_FORMAT_MOV) ? "mov" :
"other"))) : "none"; "other"))) : "none";
_using_exif = state->exif ? "yes" : "no"; _using_exif = state->exif ? "yes" : "no";
_using_global_pointer = state->save_gp ? "yes" : "no"; _using_global_pointer = state->save_gp ? "yes" : "no";
...@@ -1196,6 +1208,8 @@ void camogm_status(camogm_state *state, char * fn, int xml) ...@@ -1196,6 +1208,8 @@ void camogm_status(camogm_state *state, char * fn, int xml)
_percent_done = 0; _percent_done = 0;
_audio_en = state->audio.set_audio_enable ? "yes" : "no"; _audio_en = state->audio.set_audio_enable ? "yes" : "no";
// convert volume to relative value in percent
_audio_vol = (state->audio.audio_volume * 100) / DEFAULT_AUDIO_VOLUME;
if (xml) { if (xml) {
fprintf(f, "<?xml version=\"1.0\"?>\n" \ fprintf(f, "<?xml version=\"1.0\"?>\n" \
"<camogm_state>\n" \ "<camogm_state>\n" \
...@@ -1257,7 +1271,7 @@ void camogm_status(camogm_state *state, char * fn, int xml) ...@@ -1257,7 +1271,7 @@ void camogm_status(camogm_state *state, char * fn, int xml)
state->rawdev.overrun, state->rawdev.curr_pos_w, state->rawdev.curr_pos_r, _percent_done, state->rawdev.overrun, state->rawdev.curr_pos_w, state->rawdev.curr_pos_r, _percent_done,
state->writer_params.lba_start, state->writer_params.lba_current, state->writer_params.lba_end, state->writer_params.lba_start, state->writer_params.lba_current, state->writer_params.lba_end,
_audio_en, state->audio.set_audio_channels, state->audio.set_audio_rate, state->audio.set_audio_volume); _audio_en, state->audio.set_audio_channels, state->audio.set_audio_rate, _audio_vol);
FOR_EACH_PORT(int, chn) { FOR_EACH_PORT(int, chn) {
char *_active = is_chn_active(state, chn) ? "yes" : "no"; char *_active = is_chn_active(state, chn) ? "yes" : "no";
...@@ -1341,7 +1355,7 @@ void camogm_status(camogm_state *state, char * fn, int xml) ...@@ -1341,7 +1355,7 @@ void camogm_status(camogm_state *state, char * fn, int xml)
fprintf(f, "audio_enable \t%s\n", _audio_en); fprintf(f, "audio_enable \t%s\n", _audio_en);
fprintf(f, "audio_channels \t%d\n", state->audio.set_audio_channels); fprintf(f, "audio_channels \t%d\n", state->audio.set_audio_channels);
fprintf(f, "audio_rate \t%d\n", state->audio.set_audio_rate); fprintf(f, "audio_rate \t%d\n", state->audio.set_audio_rate);
fprintf(f, "audio_volume \t%d\n", state->audio.set_audio_volume); fprintf(f, "audio_volume \t%d\n", _audio_vol);
fprintf(f, "\n"); fprintf(f, "\n");
FOR_EACH_PORT(int, chn) { FOR_EACH_PORT(int, chn) {
char *_active = is_chn_active(state, chn) ? "yes" : "no"; char *_active = is_chn_active(state, chn) ? "yes" : "no";
......
...@@ -414,13 +414,13 @@ void audio_set_volume(int nvolume) ...@@ -414,13 +414,13 @@ void audio_set_volume(int nvolume)
long volume_max = 0; long volume_max = 0;
if (snd_mixer_selem_get_capture_volume_range(selem, &volume_min, &volume_max) == 0) { if (snd_mixer_selem_get_capture_volume_range(selem, &volume_min, &volume_max) == 0) {
// set volume only for capture // set volume only for capture
if (nvolume > 65535) if (nvolume > DEFAULT_AUDIO_VOLUME)
nvolume = 65535; nvolume = DEFAULT_AUDIO_VOLUME;
if (nvolume < 0) if (nvolume < 0)
nvolume = 0; nvolume = 0;
long long vol_new = volume_max; long long vol_new = volume_max;
vol_new *= nvolume; vol_new *= nvolume;
vol_new /= 65535; vol_new /= DEFAULT_AUDIO_VOLUME;
long vol = 0; long vol = 0;
snd_mixer_selem_get_capture_volume(selem, SND_MIXER_SCHN_FRONT_LEFT, &vol); snd_mixer_selem_get_capture_volume(selem, SND_MIXER_SCHN_FRONT_LEFT, &vol);
snd_mixer_selem_set_capture_volume_all(selem, vol_new); snd_mixer_selem_set_capture_volume_all(selem, vol_new);
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#define AUDIO_CHANNELS_MAX 2 #define AUDIO_CHANNELS_MAX 2
#define AUDIO_RATE_MIN 11025 #define AUDIO_RATE_MIN 11025
#define AUDIO_RATE_MAX 44100 #define AUDIO_RATE_MAX 44100
#define DEFAULT_AUDIO_VOLUME 0xffff #define DEFAULT_AUDIO_VOLUME 0xffff ///< absolute maximum audio volume
/** /**
* @brief Audio recording context related to stream management. * @brief Audio recording context related to stream management.
......
...@@ -58,6 +58,24 @@ ...@@ -58,6 +58,24 @@
$mode = 0777; $mode = 0777;
$sensor_ports = elphel_num_sensors(); $sensor_ports = elphel_num_sensors();
$default_imgsrv_port = 2323; $default_imgsrv_port = 2323;
// audio file for test playback; the directory with several test files should be installed with ALSA
$test_audio_file = "/usr/share/sounds/alsa/Front_Center.wav";
// the list of audio volume values
$audio_vol_list = array(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100);
/** Find closest value from the list of audio volumes */
function get_closest_volume($vol)
{
global $audio_vol_list;
$closest = null;
foreach ($audio_vol_list as $elem) {
if ($closest === null || abs($vol - $closest) > abs($elem - $vol))
$closest = $elem;
}
return $closest;
}
/** Draw single buffer usage bar */ /** Draw single buffer usage bar */
function draw_buffer_bar($port, $ports_num) function draw_buffer_bar($port, $ports_num)
...@@ -220,9 +238,8 @@ ...@@ -220,9 +238,8 @@
fprintf($fcmd, "audio=off;\n"); fprintf($fcmd, "audio=off;\n");
fprintf($fcmd, "audio_format=%s/%s;\n", $_POST['audio_sample_rate'], $_POST['audio_channels']); fprintf($fcmd, "audio_format=%s/%s;\n", $_POST['audio_sample_rate'], $_POST['audio_channels']);
fprintf($fcmd, "audio_volume=%s;\n", $_POST['audio_volume']);
// TODO: set volume here!
if ($_POST['audio_syncmode'] == "normal") if ($_POST['audio_syncmode'] == "normal")
fprintf($fcmd, "allow_sync=disable;\n"); fprintf($fcmd, "allow_sync=disable;\n");
else else
...@@ -322,10 +339,10 @@ ...@@ -322,10 +339,10 @@
$xml_geotagging_period = substr($logdata[0]['kml_period'], 0, strlen($logdata[0]['kml_period'])); $xml_geotagging_period = substr($logdata[0]['kml_period'], 0, strlen($logdata[0]['kml_period']));
// Audio Recording // Audio Recording
$xml_audiorecording_enabled = substr($logdata[0]['audio_enable'], 1, strlen($logdata[0]['audio_enable'])-2); $xml_audiorecording_enabled = substr($logdata[0]['audio_enable'], 0, strlen($logdata[0]['audio_enable']));
$xml_audio_channels = substr($logdata[0]['audio_channels'], 1, strlen($logdata[0]['audio_channels'])-2); $xml_audio_channels = substr($logdata[0]['audio_channels'], 0, strlen($logdata[0]['audio_channels']));
$xml_audio_rate = substr($logdata[0]['audio_rate'], 1, strlen($logdata[0]['audio_rate'])-2); $xml_audio_rate = substr($logdata[0]['audio_rate'], 0, strlen($logdata[0]['audio_rate']));
$xml_audio_volume = substr($logdata[0]['audio_volume'], 1, strlen($logdata[0]['audio_volume'])-2); $xml_audio_volume = substr($logdata[0]['audio_volume'], 0, strlen($logdata[0]['audio_volume']));
$xml_audio_syncmode = substr($logdata[0]['allow_sync'], 1, strlen($logdata[0]['allow_sync'])-2); $xml_audio_syncmode = substr($logdata[0]['allow_sync'], 1, strlen($logdata[0]['allow_sync'])-2);
// Get per sensor port parameters // Get per sensor port parameters
...@@ -652,11 +669,10 @@ ...@@ -652,11 +669,10 @@
<div class="TabbedPanelsContent"> <div class="TabbedPanelsContent">
<!-- Sound --> <!-- Sound -->
<b>Audio Recording:</b><br /> <b>Audio Recording:</b><br />
<div class="small">requires external USB soundcard</div> <div class="small">requires external USB soundcard or headset</div>
<p style="color:red;">not operational yet!</p>
Detected Audio Hardware: <span id="ajax_detected_audio_hardware">loading...</span> <a href="#" onClick="check_audio_hardware();"><img src="images/reload.png" style="bottom:-2px; position:relative;"></a><br /> Detected Audio Hardware: <span id="ajax_detected_audio_hardware">loading...</span> <a href="#" onClick="check_audio_hardware();"><img src="images/reload.png" style="bottom:-2px; position:relative;"></a><br />
<br /> <br />
Test Audio Playback: <a href="#" onClick="test_audio_playback('/var/hdd/Congas.wav');"><img src="images/play_audio.png" style="position:relative; top:3px;"></a><br /> Test Audio Playback: <a href="#" onClick="test_audio_playback(' <?php echo $test_audio_file; ?> ');"><img src="images/play_audio.png" style="position:relative; top:3px;"></a><br />
<br /> <br />
<form method="POST" id="audioform"> <form method="POST" id="audioform">
<table cellspacing="5px"> <table cellspacing="5px">
...@@ -670,24 +686,23 @@ ...@@ -670,24 +686,23 @@
</td></tr> </td></tr>
<tr><td>Channels:</td><td> <tr><td>Channels:</td><td>
<select name="audio_channels" id="audio_channels" disabled> <select name="audio_channels" id="audio_channels" disabled>
<option <? if ($xml_audio_channels == 2) echo "selected"; ?>>stereo</option> <option <? if ($xml_audio_channels == 2) echo "selected"; ?> value="2">stereo</option>
<option <? if ($xml_audio_channels == 1) echo "selected"; ?>>mono</option> <option <? if ($xml_audio_channels == 1) echo "selected"; ?> value="1">mono</option>
</select> </select>
</td></tr> </td></tr>
<tr><td>Volume:</td><td> <tr><td>Volume:</td><td>
<select name="audio_volume" id="audio_volume" disabled> <select name="audio_volume" id="audio_volume" disabled>
<option value="100" <? if ($xml_audio_volume == 100) echo "selected"; ?>>100%</option> <?php
<option value="90" <? if ($xml_audio_volume == 90) echo "selected"; ?>>90%</option> $closest = get_closest_volume($xml_audio_volume);
<option value="80" <? if ($xml_audio_volume == 80) echo "selected"; ?>>80%</option> foreach (array_reverse($audio_vol_list) as $vol) {
<option value="70" <? if ($xml_audio_volume == 70) echo "selected"; ?>>70%</option> if ($closest == $vol)
<option value="60" <? if ($xml_audio_volume == 60) echo "selected"; ?>>60%</option> $sel = "selected";
<option value="50" <? if ($xml_audio_volume == 50) echo "selected"; ?>>50%</option> else
<option value="40" <? if ($xml_audio_volume == 40) echo "selected"; ?>>40%</option> $sel = "";
<option value="30" <? if ($xml_audio_volume == 30) echo "selected"; ?>>30%</option> echo "<option value=\"" . $vol . "\" " . $sel . ">" . $vol . "%</option>\n";
<option value="20" <? if ($xml_audio_volume == 20) echo "selected"; ?>>20%</option> }
<option value="10" <? if ($xml_audio_volume == 10) echo "selected"; ?>>10%</option> ?>
<option value="0" <? if ($xml_audio_volume == 0) echo "selected"; ?>>0%</option> </select>
</select> volume not working, please ignore
</td></tr> </td></tr>
<tr><td>Sync Mode:</td><td> <tr><td>Sync Mode:</td><td>
<select name="audio_syncmode" id="audio_syncmode" disabled> <select name="audio_syncmode" id="audio_syncmode" disabled>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment