svcore  1.9
FFTFileCacheWriter.h
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     Sonic Visualiser
00005     An audio file viewer and annotation editor.
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file copyright 2006-2009 Chris Cannam and QMUL.
00008     
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014 */
00015 
00016 #ifndef _FFT_FILE_CACHE_WRITER_H_
00017 #define _FFT_FILE_CACHE_WRITER_H_
00018 
00019 #include "FFTCacheStorageType.h"
00020 #include "FFTCacheWriter.h"
00021 #include "data/fileio/MatrixFile.h"
00022 
00023 class FFTFileCacheWriter : public FFTCacheWriter
00024 {
00025 public:
00026     FFTFileCacheWriter(QString fileBase,
00027                        FFTCache::StorageType storageType,
00028                        int width, int height);
00029     ~FFTFileCacheWriter();
00030 
00031     int getWidth() const;
00032     int getHeight() const;
00033 
00034     void setColumnAt(int x, float *mags, float *phases, float factor);
00035     void setColumnAt(int x, float *reals, float *imags);
00036 
00037     static int getCacheSize(int width, int height,
00038                                FFTCache::StorageType type);
00039 
00040     bool haveSetColumnAt(int x) const;
00041 
00042     void allColumnsWritten();
00043 
00044     QString getFileBase() const;
00045     FFTCache::StorageType getStorageType() const { return m_storageType; }
00046 
00047 protected:
00048     char *m_writebuf;
00049 
00050     void setNormalizationFactorToWritebuf(float newfactor) {
00051         int h = m_mfc->getHeight();
00052         if (h < m_factorSize) return;
00053         if (m_storageType != FFTCache::Compact) {
00054             ((float *)m_writebuf)[h - 1] = newfactor;
00055         } else {
00056             union {
00057                 float f;
00058                 uint16_t u[2];
00059             } factor;
00060             factor.f = newfactor;
00061             ((uint16_t *)m_writebuf)[h - 2] = factor.u[0];
00062             ((uint16_t *)m_writebuf)[h - 1] = factor.u[1];
00063         }
00064     }            
00065 
00066     QString m_fileBase;
00067     FFTCache::StorageType m_storageType;
00068     int m_factorSize;
00069     MatrixFile *m_mfc;
00070 };
00071 
00072 #endif