Пример #1
0
/*------------------------------------------------------------------------------
 *  Read from the audio source
 *----------------------------------------------------------------------------*/
unsigned int
JackDspSource :: read (   void          * buf,
                          unsigned int    len )     throw ( Exception )
{
    jack_nframes_t samples         = len / 2 / getChannel();
    jack_nframes_t samples_read[2] = {0,0};
    short        * output          = (short*)buf;
    unsigned int c, n;

    if ( !isOpen() ) {
        return 0;
    }


    // Ensure the temporary buffer is big enough
    tmp_buffer = (jack_default_audio_sample_t*)realloc(tmp_buffer,
                             samples * sizeof( jack_default_audio_sample_t ) );
    if (!tmp_buffer) {
        throw Exception( __FILE__, __LINE__, "realloc on tmp_buffer failed");
    }


    for (c=0; c<getChannel(); c++)
    {    
        // Copy frames from ring buffer to temporary buffer
        // and then convert samples to output buffer
        int bytes_read = jack_ringbuffer_read(rb[c],
                                             (char*)tmp_buffer,
                              samples * sizeof( jack_default_audio_sample_t ));
        samples_read[c] = bytes_read / sizeof( jack_default_audio_sample_t );
        

        // Convert samples from float to short and put in output buffer
        for(n=0; n<samples_read[c]; n++) {
            int tmp = lrintf(tmp_buffer[n] * 32768.0f);
            if (tmp > SHRT_MAX) {
                output[n*getChannel()+c] = SHRT_MAX;
            } else if (tmp < SHRT_MIN) {
                output[n*getChannel()+c] = SHRT_MIN;
            } else {
                output[n*getChannel()+c] = (short) tmp;
            }
        }
    }

    // Didn't get as many samples as we wanted ?
    if (getChannel() == 2 && samples_read[0] != samples_read[1]) {
        Reporter::reportEvent( 2,
                              "Warning: Read a different number of samples "
                              "for left and right channels");
    }

    // Return the number of bytes put in the output buffer
    return samples_read[0] * 2 * getChannel();
}
Пример #2
0
bool PollPoller::removeChannel(Channel *channel)
{
    if(!hasChannel(channel))
        return true;

    ZL_SOCKET fd = channel->fd();
    int idx = channelIter_[channel];
    LOG_INFO("PollPoller::removeChannel [%d][%d][%0x]", fd, idx, channel);
    assert(getChannel(fd) == channel && "the remove socket must be already exist");
    assert(channel->isNoneEvent());
    assert(0 <= idx && idx < static_cast<int>(pollfds_.size()));

    const struct pollfd& pfd = pollfds_[idx];
    ZL_UNUSED(pfd);
    assert(pfd.fd == -channel->fd()-1 && pfd.events == channel->events());

    size_t n = channelMap_.erase(fd);
    ZL_UNUSED(n);
    assert(n == 1);
    if ((idx) == static_cast<int>(pollfds_.size()) - 1) // last one
    {

    }
    else
    {
        int lastfd = pollfds_.back().fd;
        iter_swap(pollfds_.begin()+idx, pollfds_.end()-1);
        if (lastfd < 0)
        {
            lastfd = -lastfd-1;
        }
        channelIter_[getChannel(lastfd)] = idx;
    }

    pollfds_.pop_back();
    channelIter_.erase(channel);

    return true;
}
Пример #3
0
ChannelList Chat::getChannelList(Player* player)
{
	ChannelList list;
	if(!player || player->isRemoved())
		return list;

	ChatChannel* channel = NULL;
	if(player->getParty() && ((channel = getChannel(player, CHANNEL_PARTY)) || (channel = createChannel(player, CHANNEL_PARTY))))
		list.push_back(channel);

	if(player->getGuildId() && player->getGuildName().length() && ((channel = getChannel(
		player, CHANNEL_GUILD)) || (channel = createChannel(player, CHANNEL_GUILD))))
		list.push_back(channel);

	for(NormalChannelMap::iterator it = m_normalChannels.begin(); it != m_normalChannels.end(); ++it)
	{
		if((channel = getChannel(player, it->first)))
			list.push_back(it->second);
	}

	bool hasPrivate = false;
	PrivateChatChannel* privChannel = NULL;
	for(PrivateChannelMap::iterator pit = m_privateChannels.begin(); pit != m_privateChannels.end(); ++pit)
	{
		if(!(privChannel = pit->second))
			continue;

		if(privChannel->isInvited(player))
			list.push_back(privChannel);

		if(privChannel->getOwner() == player->getGUID())
			hasPrivate = true;
	}

	if(!hasPrivate && player->isPremium())
		list.push_front(dummyPrivate);

	return list;
}
Пример #4
0
/**
 ChannelManager::handleTopic

 handle TOPIC
*/
void ChannelManager::handleTopic(nstring::str &nick, nstring::str &chan, nstring::str &topic)
{
	Channel* channel = getChannel(chan);
	// get channel
	
	channel->topic = topic;
	channel->topicSetter = nick;
	
	instance->log(MISC, "handleTopic(): " + nick + " has changed the topic for " + chan + " to (" + topic + ")");
	// log things, ie NETWORK
	
	FOREACH_MODULE(instance, &Module::onTopic, nick, chan, topic);
}
Пример #5
0
void SoundManager::getChannelPosition(const ChannelHandle &handle, float &x, float &y, float &z) {
	Common::StackLock lock(_mutex);

	Channel *channel = getChannel(handle);
	if (!channel || !channel->stream)
		throw Common::Exception("Invalid channel");

	if (channel->stream->getChannels() > 1)
		throw Common::Exception("Cannot get position of a non-mono sound.");

	if (_hasSound)
		alGetSource3f(channel->source, AL_POSITION, &x, &y, &z);
}
Пример #6
0
	void AudioPlayer::setSoundFreq( SoundID sID , float freqFactor )
	{
		if ( sID == ERROR_SOUND_ID )
			return;

		Channel* channel = getChannel( sID );
		if ( !channel )
			return;

		float freq;
		FMOD_Channel_GetFrequency( channel , &freq );
		FMOD_Channel_SetFrequency( channel , freqFactor * freq );
	}
Пример #7
0
std::string Chat::getChannelName(Player* player, const uint16_t& channelId)
{
	ChatChannel* channel = getChannel(player, channelId);

	if (channel)
	{
		return channel->getName();
	}
	else
	{
		return "";
	}
}
Пример #8
0
void AnimationTarget::destroyAnimation(const char* id)
{
    // Find the animation with the specified ID.
    Animation::Channel* channel = getChannel(id);
    if (channel == NULL)
        return;

    // Remove this target's channel from animation, and from the target's list of channels.
    channel->_animation->removeChannel(channel);
    removeChannel(channel);

    SAFE_DELETE(channel);
}
Пример #9
0
bool FModSound::getMute(UInt32 ChannelID) const
{
    bool muteValue(false);
    FMOD::Channel* channel(getChannel(ChannelID));
    if(channel != NULL)
    {
        FMOD_RESULT result;
        result = channel->getMute(&muteValue);
        FMOD_ERRCHECK(result,"FModSound::getMute()");
    }
    
    return muteValue;
}
Пример #10
0
bool FModSound::isPaused(UInt32 ChannelID) const
{
    bool paused(false);
    FMOD::Channel* channel(getChannel(ChannelID));
    if(channel != NULL)
    {
        FMOD_RESULT result;
        result = channel->getPaused(&paused);
        FMOD_ERRCHECK(result,"FModSound::isPause()");
    }
    
    return paused;
}
Пример #11
0
/*------------------------------------------------------------------------------
 *  Check wether read() would return anything
 *----------------------------------------------------------------------------*/
bool
JackDspSource :: canRead ( unsigned int   sec,
                           unsigned int   usec )    throw ( Exception )
{
    const unsigned int max_wait_time  = sec * 1000000;
    const unsigned int wait_increment = 10000;
    unsigned int       cur_wait       = 0;

    if ( !isOpen() ) {
        return false;
    }

    while (max_wait_time > cur_wait) {
        bool canRead = true;

        for (unsigned int c = 0 ; c < getChannel() ; c++) {
            if (jack_ringbuffer_read_space(rb[c]) <= 0) {
                canRead = false;
            }
        }

        if (canRead) {
            return true;
        }

        cur_wait += wait_increment;
        usleep ( wait_increment );
    }

    usleep( usec );
    for (unsigned int c = 0 ; c < getChannel() ; c++) {
        if (jack_ringbuffer_read_space(rb[c]) <= 0) {
            return false;
        }
    }

    return true;
}
Пример #12
0
void channelDist(Mat& hsv, Mat& dist, int hueVal, int channel)
{
	Mat channelImg;
	getChannel(hsv, channelImg, channel);
	if (channel == 0)
	{
		Mat dist1, dist2;
		absdiff(channelImg, hueVal, dist1);
		absdiff(channelImg, hueVal + ((hueVal < 90) ? 180 : -180), dist2);
		min(dist1, dist2, dist);
	}
	else
		absdiff(channelImg, hueVal, dist);
}
void GraphicsKeyboardItem::mousePressEvent ( QGraphicsSceneMouseEvent *event )
{
    Q_ASSERT(!activeKey);
    for (int i = 0; i < keys.size(); i++) {
        if (keys[i]->contains(event->pos())) {
            activeKey = keys[i];
            activeKey->pressKey();
            activeKeyIndex = i;
            keyPressed(getChannel(), activeKeyIndex, 127);
            return;
        }
    }
    event->ignore();
}
Пример #14
0
void FModSound::stop(UInt32 ChannelID)
{
    FMOD::Channel* channel(getChannel(ChannelID));
    if(channel != NULL && isPlaying(ChannelID))
    {
        FMOD_RESULT result;
        result = channel->stop();
        FMOD_ERRCHECK(result,"FModSound::stop()");
        if(result == FMOD_OK)
        {
            produceSoundStopped(ChannelID);
        }
    }
}
Пример #15
0
/**
 ChannelManager::handleMode

 handle TMODE changes, etc.
*/
void ChannelManager::handleMode(nstring::str &uid, nstring::str &chan, nstring::str &modes)
{
	irc::modes modeContainer;
	irc::params paramContainer;
	instance->modeParser->sortModes(modes, modeContainer, paramContainer, true);
	// parse modes

	Channel* channel = getChannel(chan);
	instance->modeParser->saveModes(channel, modeContainer, paramContainer);
	// update the modes in our channel record
	
	FOREACH_MODULE(instance, &Module::onCMode, chan, modeContainer, paramContainer);
	// TODO
}
Пример #16
0
bool Chat::removeUserFromChannel(Player* player, uint16_t channelId)
{
	ChatChannel* channel = getChannel(player, channelId);

	if (channel && channel->removeUser(player)) {
		if (channel->getOwner() == player->getGUID()) {
			deleteChannel(player, channelId);
		}

		return true;
	}

	return false;
}
Пример #17
0
void FModSound::seek(Real32 pos, UInt32 ChannelID)
{
    FMOD::Channel* channel(getChannel(ChannelID));
    if(channel != NULL)
    {
        unsigned int position(pos * 1000.0);

        FMOD_RESULT result;
        result = channel->setPosition(position, FMOD_TIMEUNIT_MS);
        FMOD_ERRCHECK(result,"FModSound::seek()");

        produceSoundSeeked(ChannelID);
    }
}
Пример #18
0
void FModSound::unpause(UInt32 ChannelID)
{
    FMOD::Channel* channel(getChannel(ChannelID));
    if(channel != NULL && isPaused(ChannelID))
    {
        FMOD_RESULT result;
        result = channel->setPaused(false);
        FMOD_ERRCHECK(result,"FModSound::unpause()");
        if(result == FMOD_OK)
        {
            produceSoundUnpaused(ChannelID);
        }
    }
}
Пример #19
0
ChatChannel* Chat::createChannel(const Player& player, uint16_t channelId)
{
	if (getChannel(player, channelId)) {
		return NULL;
	}

	switch (channelId) {
		case CHANNEL_GUILD: {
			Guild* guild = player.getGuild();
			if (guild) {
				ChatChannel* newChannel = new ChatChannel(channelId, guild->getName());
				guildChannels[guild->getId()] = newChannel;
				return newChannel;
			}
			break;
		}

		case CHANNEL_PARTY: {
			Party* party = player.getParty();
			if (party) {
				ChatChannel* newChannel = new ChatChannel(channelId, "Party");
				partyChannels[party] = newChannel;
				return newChannel;
			}
			break;
		}

		case CHANNEL_PRIVATE: {
			//only 1 private channel for each premium player
			if (!player.isPremium() || getPrivateChannel(player)) {
				return NULL;
			}

			//find a free private channel slot
			for (uint16_t i = 100; i < 10000; ++i) {
				if (privateChannels.find(i) == privateChannels.end()) {
					PrivateChatChannel* newChannel = new PrivateChatChannel(i, player.getName() + "'s Channel");
					newChannel->setOwner(player.getGUID());
					privateChannels[i] = newChannel;
					return newChannel;
				}
			}
			break;
		}

		default:
			break;
	}
	return NULL;
}
Пример #20
0
bool FModSound::isPlaying(UInt32 ChannelID) const
{
    bool playing(false);
    FMOD::Channel* channel(getChannel(ChannelID));
    if(channel != NULL)
    {
        FMOD_RESULT result;
        result = channel->isPlaying(&playing);
        FMOD_ERRCHECK(result,"FModSound::isPlaying()");
    }
    
    return playing;
    
}
Пример #21
0
String MidiMessage::getDescription() const
{
    if (isNoteOn())           return "Note on "  + MidiMessage::getMidiNoteName (getNoteNumber(), true, true, 3) + " Velocity " + String (getVelocity()) + " Channel " + String (getChannel());
    if (isNoteOff())          return "Note off " + MidiMessage::getMidiNoteName (getNoteNumber(), true, true, 3) + " Velocity " + String (getVelocity()) + " Channel " + String (getChannel());
    if (isProgramChange())    return "Program change " + String (getProgramChangeNumber()) + " Channel " + String (getChannel());
    if (isPitchWheel())       return "Pitch wheel " + String (getPitchWheelValue()) + " Channel " + String (getChannel());
    if (isAftertouch())       return "Aftertouch " + MidiMessage::getMidiNoteName (getNoteNumber(), true, true, 3) +  ": " + String (getAfterTouchValue()) + " Channel " + String (getChannel());
    if (isChannelPressure())  return "Channel pressure " + String (getChannelPressureValue()) + " Channel " + String (getChannel());
    if (isAllNotesOff())      return "All notes off Channel " + String (getChannel());
    if (isAllSoundOff())      return "All sound off Channel " + String (getChannel());
    if (isMetaEvent())        return "Meta event";

    if (isController())
    {
        String name (MidiMessage::getControllerName (getControllerNumber()));

        if (name.isEmpty())
            name = String (getControllerNumber());

        return "Controller " + name + ": " + String (getControllerValue()) + " Channel " + String (getChannel());
    }

    return String::toHexString (getRawData(), getRawDataSize());
}
Пример #22
0
void HDF5Recording::endChannelBlock(bool lastBlock)
{
	int nCh = channelTimestampArray.size();
	for (int ch = 0; ch < nCh; ++ch)
	{
		int tsSize = channelTimestampArray[ch]->size();
		if ((tsSize > 0) && ((tsSize > CHANNEL_TIMESTAMP_MIN_WRITE) || lastBlock))
		{
			int realChan = getRealChannel(ch);
			int index = processorMap[getChannel(realChan)->recordIndex];
			fileArray[index]->writeTimestamps(channelTimestampArray[ch]->getRawDataPointer(), tsSize, recordedChanToKWDChan[ch]);
			channelTimestampArray[ch]->clearQuick();
		}
	}
}
Пример #23
0
void Board::rebuildMessagesTree()
{
  if (!_messages.isEmpty())
  {
    QList<shared_ptr<BoardMessage> > msg = _messages.values();
    QList<shared_ptr<BoardMessage> >::const_iterator it;
    for (it = msg.constBegin(); it != msg.constEnd(); ++it)
    {
      if ((*it)->parentId() == -1)
        (*it)->setParent(getChannel((*it)->channelId()).get());
      else
        (*it)->setParent(getMessage((*it)->parentId()).get());
    }
  }
}
Пример #24
0
void OriginalRecording::openFiles(File rootFolder, int experimentNumber, int recordingNumber)
{
    this->recordingNumber = recordingNumber;
    this->experimentNumber = experimentNumber;

	processorArray.clear();
	lastProcId = 0;

    openFile(rootFolder,nullptr);
    openMessageFile(rootFolder);
    for (int i = 0; i < fileArray.size(); i++)
    {
        if (getChannel(i)->getRecordState())
        {
            openFile(rootFolder,getChannel(i));
        }
    }
    for (int i = 0; i < spikeFileArray.size(); i++)
    {
        openSpikeFile(rootFolder,getSpikeElectrode(i));
    }
    blockIndex = 0;
	startTimestamp = timestamp;
}
Пример #25
0
	//------------------------------------------------------------------------
	Result EventManager::createChannel(const std::string& name)
	{
		// check first whenever such a channel is already in the database
		if (getChannel(name)) return EVENT_CHANNEL_EXISTS;

		// channel is not in the database, so create it and fill it's data
		SharedPtr<EventChannel> channel(new EventChannel(this, name));

		// push the channel into the database
		mChannelDb[name] = channel;
		NR_Log(Log::LOG_ENGINE, "EventManager: New channel \"%s\" created", name.c_str());

		// OK
		return OK;
	}
inline deUint32 bilinearSample (const ConstPixelBufferAccess& src, float u, float v)
{
	int w = src.getWidth();
	int h = src.getHeight();

	int x0 = deFloorFloatToInt32(u-0.5f);
	int x1 = x0+1;
	int y0 = deFloorFloatToInt32(v-0.5f);
	int y1 = y0+1;

	int i0 = de::clamp(x0, 0, w-1);
	int i1 = de::clamp(x1, 0, w-1);
	int j0 = de::clamp(y0, 0, h-1);
	int j1 = de::clamp(y1, 0, h-1);

	float a = deFloatFrac(u-0.5f);
	float b = deFloatFrac(v-0.5f);

	deUint32 p00	= readUnorm8<NumChannels>(src, i0, j0);
	deUint32 p10	= readUnorm8<NumChannels>(src, i1, j0);
	deUint32 p01	= readUnorm8<NumChannels>(src, i0, j1);
	deUint32 p11	= readUnorm8<NumChannels>(src, i1, j1);
	deUint32 dst	= 0;

	// Interpolate.
	for (int c = 0; c < NumChannels; c++)
	{
		float f = (getChannel(p00, c)*(1.0f-a)*(1.0f-b)) +
				  (getChannel(p10, c)*(     a)*(1.0f-b)) +
				  (getChannel(p01, c)*(1.0f-a)*(     b)) +
				  (getChannel(p11, c)*(     a)*(     b));
		dst = setChannel(dst, c, roundToUint8Sat(f));
	}

	return dst;
}
Пример #27
0
bool Chat::talkToChannel(Player* player, SpeakClass type, const std::string& text, uint16_t channelId)
{
  ChatChannel *channel = getChannel(player, channelId);
  if(!channel) {
    return false;
  }

  switch(channelId){
    case CHANNEL_HELP:
    {
      // Help channel
      if(type == SPEAK_CHANNEL_Y && player->hasFlag(PlayerFlag_TalkOrangeHelpChannel)){
        type = SPEAK_CHANNEL_O;
      }
      break;
    }
    // Players can't speak in these channels while they're level 1
    // Also, there is a delay of 2 minutes for trade and trade rook
    case CHANNEL_TRADE:
    case CHANNEL_TRADE_ROOK:
    case CHANNEL_RL_CHAT:
    case CHANNEL_GAME_CHAT:
    {
      if(!player->hasFlag(PlayerFlag_CannotBeMuted)){
        if(player->getLevel() < 2){
          player->sendCancel("You may not speak into channels as long as you are on level 1.");
          return true;
          break;
        }
        else if((channelId == CHANNEL_TRADE || channelId == CHANNEL_TRADE_ROOK) && player->hasCondition(CONDITION_MUTED_CHAT_TRADE)){
          player->sendCancel("You may only place one offer in two minutes.");
          return true;
          break;
        }
      }
    }
    default:
    {
      break;
    }
  }

  if(channel->talk(player, type, text)){
    return true;
  }

  return false;
}
Пример #28
0
/*------------------------------------------------------------------------------
 *  Open the audio source
 *----------------------------------------------------------------------------*/
bool
SerialUlaw :: open ( void )                       throw ( Exception )
{
    struct termios    ts;

    if ( isOpen() ) {
        return false;
    }

    switch ( getBitsPerSample() ) {
        case 16:
            break;

        default:
            return false;
    }

    if (getChannel() != 1) {
        reportEvent(3, "Only mono input supported for Serial ULaw");
        return false;
    }
    if (getSampleRate() != 8000) {
        reportEvent(3, "Only 8000 Hz sample rate supported for Serial ULaw");
        return false;
    }

    if ( (fileDescriptor = ::open( fileName, O_RDONLY)) == -1 ) {
        fileDescriptor = 0;
        return false;
    }

    if(tcgetattr(fileDescriptor, &ts) < 0) {
        close();
        throw Exception( __FILE__, __LINE__, "can't get tty settings");
    }

    cfsetispeed(&ts, B115200);
    cfmakeraw(&ts);
    ts.c_cflag |= CLOCAL;
    if(tcsetattr(fileDescriptor, TCSANOW, &ts) < 0) {
        close();
        throw Exception( __FILE__, __LINE__, "can't set tty settings");
    }

    tcflush(fileDescriptor, TCIFLUSH);

    return true;
}
Пример #29
0
ChatChannel* Chat::createChannel(const Player& player, uint16_t channelId)
{
	if (getChannel(player, channelId)) {
		return nullptr;
	}

	switch (channelId) {
		case CHANNEL_GUILD: {
			Guild* guild = player.getGuild();
			if (guild) {
				auto ret = guildChannels.emplace(std::make_pair(guild->getId(), ChatChannel(channelId, guild->getName())));
				return &ret.first->second;
			}
			break;
		}

		case CHANNEL_PARTY: {
			Party* party = player.getParty();
			if (party) {
				auto ret = partyChannels.emplace(std::make_pair(party, ChatChannel(channelId, "Party")));
				return &ret.first->second;
			}
			break;
		}

		case CHANNEL_PRIVATE: {
			//only 1 private channel for each premium player
			if (!player.isPremium() || getPrivateChannel(player)) {
				return nullptr;
			}

			//find a free private channel slot
			for (uint16_t i = 100; i < 10000; ++i) {
				auto ret = privateChannels.emplace(std::make_pair(i, PrivateChatChannel(i, player.getName() + "'s Channel")));
				if (ret.second) { //second is a bool that indicates that a new channel has been placed in the map
					auto& newChannel = (*ret.first).second;
					newChannel.setOwner(player.getGUID());
					return &newChannel;
				}
			}
			break;
		}

		default:
			break;
	}
	return nullptr;
}
Пример #30
0
void MyRootAsyncClient::sync_do_root(apache::thrift::RpcOptions& rpcOptions) {
  apache::thrift::ClientReceiveState _returnState;
  std::unique_ptr<apache::thrift::RequestCallback> callback0(new apache::thrift::ClientSyncCallback(&_returnState, getChannel()->getEventBase(), false));
  do_root(rpcOptions, std::move(callback0));
  getChannel()->getEventBase()->loopForever();
  SCOPE_EXIT {
    if (_returnState.header() && !_returnState.header()->getHeaders().empty()) {
      rpcOptions.setReadHeaders(_returnState.header()->releaseHeaders());
    }
  };
  if (!_returnState.buf()) {
    assert(_returnState.exception());
    std::rethrow_exception(_returnState.exception());
  }
  recv_do_root(_returnState);
}