r3880 - trunk/bse
- From: timj svn gnome org
- To: svn-commits-list gnome org
- Subject: r3880 - trunk/bse
- Date: Sun, 10 Sep 2006 16:48:26 -0400 (EDT)
Author: timj
Date: 2006-09-10 16:48:03 -0400 (Sun, 10 Sep 2006)
New Revision: 3880
Modified:
trunk/bse/ChangeLog
trunk/bse/gsldatautils.c
trunk/bse/gsldatautils.h
Log:
Sun Sep 10 22:46:55 2006 Tim Janik <timj gtk org>
* gsldatautils.h, gsldatautils.c: added bse_wave_file_from_fbuffer() and
bse_wave_file_from_dbuffer() to easily save WAV files from memory.
Modified: trunk/bse/ChangeLog
===================================================================
--- trunk/bse/ChangeLog 2006-09-10 20:42:06 UTC (rev 3879)
+++ trunk/bse/ChangeLog 2006-09-10 20:48:03 UTC (rev 3880)
@@ -1,3 +1,8 @@
+Sun Sep 10 22:46:55 2006 Tim Janik <timj gtk org>
+
+ * gsldatautils.h, gsldatautils.c: added bse_wave_file_from_fbuffer() and
+ bse_wave_file_from_dbuffer() to easily save WAV files from memory.
+
Sat Jul 15 20:06:24 2006 Tim Janik <timj gtk org>
* gslwaveosc-aux.c: use doubles instead of floats to store temporary
Modified: trunk/bse/gsldatautils.c
===================================================================
--- trunk/bse/gsldatautils.c 2006-09-10 20:42:06 UTC (rev 3879)
+++ trunk/bse/gsldatautils.c 2006-09-10 20:48:03 UTC (rev 3880)
@@ -21,6 +21,9 @@
#include <string.h>
#include <unistd.h>
#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#define BSIZE GSL_DATA_HANDLE_PEEK_BUFFER /* FIXME: global buffer size setting */
@@ -234,7 +237,69 @@
return 0;
}
+static gint /* errno */
+bse_wave_file_from_bbuffer (const char *file_name,
+ guint n_bits,
+ guint n_channels,
+ guint sample_freq,
+ guint n_values,
+ guint n_bytes,
+ const uint8 *bytes)
+{
+ g_return_val_if_fail (file_name != NULL, EINVAL);
+ g_return_val_if_fail (n_bits == 16 || n_bits == 8, EINVAL);
+ int fd = open (file_name, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+ if (fd < 0)
+ return errno;
+ bse_wave_file_dump_header (fd, n_values * n_bits / 8, n_bits, n_channels, sample_freq);
+ GslLong j;
+ do
+ j = write (fd, bytes, n_bytes);
+ while (j < 0 && errno == EINTR);
+ int err = errno;
+ int cs = close (fd);
+ if (j < 0)
+ return err ? err : EIO;
+ if (cs < 0)
+ return errno ? errno : EIO;
+ return 0;
+}
+
gint /* errno */
+bse_wave_file_from_fbuffer (const char *file_name,
+ guint n_bits,
+ guint n_channels,
+ guint sample_freq,
+ guint n_values,
+ const gfloat *values)
+{
+ g_return_val_if_fail (n_bits == 16 || n_bits == 8, EINVAL);
+ void *buffer = g_new (guint32, n_values);
+ GslLong n = gsl_conv_from_float_clip (n_bits > 8 ? GSL_WAVE_FORMAT_SIGNED_16 : GSL_WAVE_FORMAT_UNSIGNED_8,
+ G_LITTLE_ENDIAN, values, buffer, n_values);
+ int retval = bse_wave_file_from_bbuffer (file_name, n_bits, n_channels, sample_freq, n_values, n, buffer);
+ g_free (buffer);
+ return retval;
+}
+
+gint /* errno */
+bse_wave_file_from_dbuffer (const char *file_name,
+ guint n_bits,
+ guint n_channels,
+ guint sample_freq,
+ guint n_values,
+ const gdouble *values)
+{
+ g_return_val_if_fail (n_bits == 16 || n_bits == 8, EINVAL);
+ void *buffer = g_new (guint32, n_values);
+ GslLong n = gsl_conv_from_double_clip (n_bits > 8 ? GSL_WAVE_FORMAT_SIGNED_16 : GSL_WAVE_FORMAT_UNSIGNED_8,
+ G_LITTLE_ENDIAN, values, buffer, n_values);
+ int retval = bse_wave_file_from_bbuffer (file_name, n_bits, n_channels, sample_freq, n_values, n, buffer);
+ g_free (buffer);
+ return retval;
+}
+
+gint /* errno */
gsl_data_handle_dump_wav (GslDataHandle *dhandle,
gint fd,
guint n_bits,
Modified: trunk/bse/gsldatautils.h
===================================================================
--- trunk/bse/gsldatautils.h 2006-09-10 20:42:06 UTC (rev 3879)
+++ trunk/bse/gsldatautils.h 2006-09-10 20:48:03 UTC (rev 3880)
@@ -73,6 +73,15 @@
gint fd,
GslWaveFormatType format,
guint byte_order);
+gint /* errno */ gsl_data_handle_dump_wav (GslDataHandle *dhandle,
+ gint fd,
+ guint n_bits,
+ guint n_channels,
+ guint sample_freq);
+void gsl_data_handle_dump_wstore(GslDataHandle *dhandle,
+ SfiWStore *wstore,
+ GslWaveFormatType format,
+ guint byte_order);
gint /* errno */ bse_wave_file_dump_header (gint fd,
guint n_data_bytes,
guint n_bits,
@@ -80,21 +89,23 @@
guint sample_freq);
gint /* errno */ bse_wave_file_patch_length (gint fd,
guint n_data_bytes);
-gint /* errno */ gsl_data_handle_dump_wav (GslDataHandle *dhandle,
- gint fd,
- guint n_bits,
- guint n_channels,
- guint sample_freq);
gint /* errno */ bse_wave_file_dump_data (gint fd,
guint n_bits,
guint n_values,
const gfloat *values);
-void gsl_data_handle_dump_wstore(GslDataHandle *dhandle,
- SfiWStore *wstore,
- GslWaveFormatType format,
- guint byte_order);
+gint /* errno */ bse_wave_file_from_fbuffer (const char *file_name,
+ guint n_bits,
+ guint n_channels,
+ guint sample_freq,
+ guint n_values,
+ const gfloat *values);
+gint /* errno */ bse_wave_file_from_dbuffer (const char *file_name,
+ guint n_bits,
+ guint n_channels,
+ guint sample_freq,
+ guint n_values,
+ const gdouble *values);
-
/* --- conversion utils --- */
static inline guint gsl_conv_from_float (GslWaveFormatType format,
guint byte_order,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]