Example #1
0
static gboolean save_winamp_file (const gchar * filename)
{
    VFSFile *file;

    gchar name[257];
    gint i;
    guchar bands[11];

    if (!(file = open_vfs_file(filename, "wb")))
        return FALSE;

    if (vfs_fwrite ("Winamp EQ library file v1.1\x1a!--", 1, 31, file) != 31)
        goto ERR;

    memset(name, 0, 257);
    g_strlcpy(name, "Entry1", 257);

    if (vfs_fwrite (name, 1, 257, file) != 257)
        goto ERR;

    for (i = 0; i < AUD_EQUALIZER_NBANDS; i++)
        bands[i] = 63 - (((equalizerwin_get_band(i) + EQUALIZER_MAX_GAIN) * 63) / EQUALIZER_MAX_GAIN / 2);

    bands[AUD_EQUALIZER_NBANDS] = 63 - (((equalizerwin_get_preamp() + EQUALIZER_MAX_GAIN) * 63) / EQUALIZER_MAX_GAIN / 2);

    if (vfs_fwrite (bands, 1, 11, file) != 11)
        goto ERR;

    vfs_fclose (file);
    return TRUE;

ERR:
    vfs_fclose (file);
    return FALSE;
}
Example #2
0
static gint wav_open(void)
{
    memcpy(&header.main_chunk, "RIFF", 4);
    header.length = GUINT32_TO_LE(0);
    memcpy(&header.chunk_type, "WAVE", 4);
    memcpy(&header.sub_chunk, "fmt ", 4);
    header.sc_len = GUINT32_TO_LE(16);
    header.format = GUINT16_TO_LE(1);
    header.modus = GUINT16_TO_LE(input.channels);
    header.sample_fq = GUINT32_TO_LE(input.frequency);
    if (input.format == FMT_U8 || input.format == FMT_S8)
        header.bit_p_spl = GUINT16_TO_LE(8);
    else
        header.bit_p_spl = GUINT16_TO_LE(16);
    header.byte_p_sec = GUINT32_TO_LE(input.frequency * header.modus * (GUINT16_FROM_LE(header.bit_p_spl) / 8));
    header.byte_p_spl = GUINT16_TO_LE((GUINT16_FROM_LE(header.bit_p_spl) / (8 / input.channels)));
    memcpy(&header.data_chunk, "data", 4);
    header.data_length = GUINT32_TO_LE(0);

    if (vfs_fwrite (& header, 1, sizeof header, output_file) != sizeof header)
        return 0;

    written = 0;

    return 1;
}
bool_t save_preset_file (EqualizerPreset * preset, const char * filename)
{
    GKeyFile *rcfile;
    int i;
    char *data;
    gsize len;
    GError *error = NULL;

    rcfile = g_key_file_new();
    g_key_file_set_double(rcfile, "Equalizer preset", "Preamp", preset->preamp);

    for (i = 0; i < 10; i++) {
        char tmp[7];
        g_snprintf(tmp, sizeof(tmp), "Band%d", i);
        g_key_file_set_double(rcfile, "Equalizer preset", tmp,
                              preset->bands[i]);
    }

    data = g_key_file_to_data(rcfile, &len, &error);

    bool_t success = FALSE;

    VFSFile * file = vfs_fopen (filename, "w");
    if (file == NULL)
        goto DONE;
    if (vfs_fwrite (data, 1, strlen (data), file) == strlen (data))
        success = TRUE;
    vfs_fclose (file);

DONE:
    g_free(data);
    g_key_file_free(rcfile);
    return success;
}
Example #4
0
gboolean copy_vfs (VFSFile * in, VFSFile * out)
{
    if (vfs_fseek (in, 0, SEEK_SET) < 0 || vfs_fseek (out, 0, SEEK_SET) < 0)
        return FALSE;

    gchar * buffer = g_malloc (COPY_BUF);
    gint64 size = 0, readed;

    while ((readed = vfs_fread (buffer, 1, COPY_BUF, in)) > 0)
    {
        if (vfs_fwrite (buffer, 1, readed, out) != readed)
            goto FAILED;

        size += readed;
    }

    if (vfs_ftruncate (out, size) < 0)
        goto FAILED;

    g_free (buffer);
    return TRUE;

FAILED:
    g_free (buffer);
    return FALSE;
}
Example #5
0
static FLAC__StreamEncoderWriteStatus flac_write_cb(const FLAC__StreamEncoder *encoder,
    const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, gpointer data)
{
    if (vfs_fwrite (buffer, 1, bytes, data) != bytes)
        return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;

    return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
}
Example #6
0
/**
 * Writes a character to a stream.
 *
 * @param c A character to write to the stream.
 * @param stream A #VFSFile object representing the stream.
 * @return The character on success, or EOF.
 */
EXPORT int vfs_fputc(int c, VFSFile *stream)
{
    unsigned char uc = (unsigned char) c;

    if (!vfs_fwrite(&uc, 1, 1, stream)) {
        return EOF;
    }

    return uc;
}
Example #7
0
static void wav_close(void)
{
    if (output_file)
    {
        header.length = GUINT32_TO_LE(written + sizeof (struct wavhead) - 8);
        header.data_length = GUINT32_TO_LE(written);

        if (vfs_fseek (output_file, 0, SEEK_SET) || vfs_fwrite (& header, 1,
         sizeof header, output_file) != sizeof header)
            fprintf (stderr, "Error while writing to .wav output file.\n");
    }
}
Example #8
0
static bool_t write_key_raw (VFSFile * file, const char * key, const char * val)
{
    int keylen = strlen (key);
    int vallen = strlen (val);
    char buf[keylen + vallen + 2];

    memcpy (buf, key, keylen);
    buf[keylen] = '=';
    memcpy (buf + keylen + 1, val, vallen);
    buf[keylen + vallen + 1] = '\n';

    return (vfs_fwrite (buf, 1, keylen + vallen + 2, file) == keylen + vallen + 2);
}
Example #9
0
static bool_t write_frame (VFSFile * handle, GenericFrame * frame, int *
 frame_size)
{
    TAGDBG ("Writing frame %s, size %d\n", frame->key, frame->size);

    ID3v2FrameHeader header;

    memcpy (header.key, frame->key, 4);
    header.size = syncsafe32 (frame->size);
    header.size = GUINT32_TO_BE (header.size);
    header.flags = 0;

    if (vfs_fwrite (& header, 1, sizeof (ID3v2FrameHeader), handle) != sizeof
     (ID3v2FrameHeader))
        return FALSE;

    if (vfs_fwrite (frame->data, 1, frame->size, handle) != frame->size)
        return FALSE;

    * frame_size = sizeof (ID3v2FrameHeader) + frame->size;
    return TRUE;
}
Example #10
0
static bool_t write_header (VFSFile * handle, int size, bool_t is_footer)
{
    ID3v2Header header;

    memcpy (header.magic, is_footer ? "3DI" : "ID3", 3);
    header.version = 4;
    header.revision = 0;
    header.flags = ID3_HEADER_HAS_FOOTER;
    header.size = syncsafe32 (size);
    header.size = GUINT32_TO_BE (header.size);

    return vfs_fwrite (& header, 1, sizeof (ID3v2Header), handle) == sizeof
     (ID3v2Header);
}
Example #11
0
void RandomAccessFile_write (JNIEnv *env, w_instance thisRAF, w_int oneByte) {
  vfs_FILE    *file;
  w_sbyte     minibuf = oneByte;

  file = RAF2FILE(thisRAF);
  
  if(file == NULL) {
    throwNullPointerException(JNIEnv2w_thread(env));
  } else {
    vfs_fseek(file, vfs_ftell(file), SEEK_SET);
    vfs_fwrite(&minibuf, 1, 1, file);
    vfs_fflush(file);
  }
}
Example #12
0
void RandomAccessFile_writeFromBuffer (JNIEnv *env, w_instance thisRAF, w_instance buffer, w_int offset, w_int length) {
  vfs_FILE    *file;
  w_sbyte     *bytes;
  w_sbyte     *data;

  if ((offset < 0) || (offset > instance2Array_length(buffer) - length)) {
    throwArrayIndexOutOfBoundsException(JNIEnv2w_thread(env));

    return;
  }

  bytes = instance2Array_byte(buffer);
  file = RAF2FILE(thisRAF);
  
  if(file == NULL) {
    throwNullPointerException(JNIEnv2w_thread(env));
  } else {
    data = bytes + offset;
    vfs_fwrite(data, 1, (w_word)length, file);
    vfs_fflush(file);
  }
}
Example #13
0
static gint write_cb (void * file, const gchar * buf, gint len)
{
    return vfs_fwrite (buf, 1, len, file);
}
Example #14
0
static int32_t wv_write_bytes(void *id, void *data, int32_t bcount)
{
    return vfs_fwrite(data, 1, bcount, (VFSFile *) id);
}
Example #15
0
static gint file_write_output (void * data, gint length)
{
    return vfs_fwrite (data, 1, length, output_file);
}
Example #16
0
static void wav_write (void * data, gint len)
{
    written += len;
    if (vfs_fwrite (data, 1, len, output_file) != len)
        fprintf (stderr, "Error while writing to .wav output file.\n");
}
Example #17
0
static size_t write_cb(const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle)
{
    return vfs_fwrite(ptr, size, nmemb, handle);
}
Example #18
0
/**
 * Writes an unsigned 64-bit native endian value into the stream as a
 * Big Endian value.
 *
 * @param value Value to write into the stream.
 * @param stream A #VFSFile object representing the stream.
 * @return TRUE if read was succesful, FALSE if there was an error.
 */
EXPORT bool_t vfs_fput_be64(uint64_t value, VFSFile *stream)
{
    uint64_t tmp = GUINT64_TO_BE(value);
    return vfs_fwrite(&tmp, sizeof(tmp), 1, stream) == 1;
}
Example #19
0
/**
 * Writes an unsigned 32-bit native endian value into the stream as a
 * Big Endian value.
 *
 * @param value Value to write into the stream.
 * @param stream A #VFSFile object representing the stream.
 * @return TRUE if read was succesful, FALSE if there was an error.
 */
EXPORT bool_t vfs_fput_le32(uint32_t value, VFSFile *stream)
{
    uint32_t tmp = GUINT32_TO_LE(value);
    return vfs_fwrite(&tmp, sizeof(tmp), 1, stream) == 1;
}
Example #20
0
/**
 * Writes a string to a VFS stream.
 *
 * @param s A string to write to the stream.
 * @param stream A #VFSFile object representing the stream.
 * @return The amount of bytes written.
 */
EXPORT int vfs_fputs(const char *s, VFSFile *stream)
{
    gsize n = strlen(s);

    return ((vfs_fwrite(s, 1, n, stream) == n) ? n : EOF);
}
Example #21
0
static void write_byte(void *obj, int data)
{
	VFSFile *file = (VFSFile *) obj;
	const char buf[1] = { data };
	vfs_fwrite(buf, 1, 1, file);
}