static short GetShortSample(Sound *s, long i, int c) { short res = 0; if (i >= Snack_GetLength(s) || s->storeType == SOUND_IN_CHANNEL) return 0; i = i * Snack_GetNumChannels(s) + c; if (s->storeType == SOUND_IN_MEMORY) { res = (short) FSAMPLE(s, i); } else { if (s->linkInfo.linkCh == NULL) { OpenLinkedFile(s, &s->linkInfo); } res = (short) GetSample(&s->linkInfo, i); } if (Snack_GetSampleEncoding(s) == LIN8) { res <<= 8; } return res; }
void ID3_Tag::RenderToHandle( void ) { uchar *buffer; luint size; if ( fileHandle ) { if ( size = Size() ) { #ifdef _DEBUG // ASSERT( size < MAX_ALLOC ); // PL #endif if ( buffer = new uchar[ size ] ) { if ( size = Render ( buffer ) ) { // if the new tag fits perfectly within the old // and the old one actually existed (ie this isn't the first tag // this file has had) if ( ( m_nOldTagSize == 0 && m_nFileSize == 0 ) || ( size == m_nOldTagSize && size != 0 ) ) { fseek ( fileHandle, 0, SEEK_SET ); fwrite ( buffer, 1, size, fileHandle ); m_nOldTagSize = size; } else { // else we gotta make a temp file, // copy the tag into it, copy the // rest of the old file after the tag, // delete the old file, rename this // new file to the old file's name // and update the fileHandle FILE *tempOut; if ( strlen ( m_strTempName ) > 0 ) { if ( tempOut = fopen ( m_strTempName, "wb" ) ) { uchar *buffer2; fwrite ( buffer, 1, size, tempOut ); fseek ( fileHandle, m_nOldTagSize, SEEK_SET ); if ( buffer2 = new uchar [ BUFF_SIZE ] ) { int i; while ( ! feof ( fileHandle ) ) { i = fread ( buffer2, 1, BUFF_SIZE, fileHandle ); fwrite ( buffer2, 1, i, tempOut ); } delete[] buffer2; } fclose ( tempOut ); fclose ( fileHandle ); // DeleteFileA( m_strFileName ); // MoveFileA( m_strTempName, m_strFileName ); OpenLinkedFile( LINK_READONLY ); m_nOldTagSize = size; } } } } delete[] buffer; } else ID3_THROW ( ID3E_NoMemory ); } } else ID3_THROW ( ID3E_NoData ); return; }